Jump to content


Photo

Validation


  • Please log in to reply
1 reply to this topic

#1 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 09 April 2006 - 09:58 PM

Hi,
I don't quite understand the following piece of code.

if(eregi("zip",$field))
{
if(!ereg("^[0-9]{5,5}(\-[0-9]{4,4})?$",$value))
{
$errors[] = "$value is not a valid zipcode.";
}
}
if(eregi("phone",$field))
{
if(!ereg("^[0-9)(xX -]{7,20}$",$value))
{
$errors[]="$value is not a valid phone number. ";
}
}


I know its the fields are being validated, but all i get for the 'zip' field is that numbers have to be between 0 and 9 and you can use ^. I dont understand what the rest of it is doing. If someone could explain it to me. The same goes for the 'phone' field. Thanks.

#2 DougieB2

DougieB2
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 09 April 2006 - 10:50 PM

^ means match the beginning of a string. [0-9]{5,5} mean match any character in the 0-9 range a minimum of 5 times and a maximum of 5 times. So match a string of 5 numbers. \- means match the - character, the \ escapes it. Then match 4 0-9's. $ matches the end of the string.

so ^12345-1234$, looks like this 12345-1234 as a string.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users