eregi, not sure why canadian postal code doesn't match
Posted: Wed Mar 26, 2008 2:36 pm
Hi,
Im trying to use regular expressions to test Canadian Postal Codes. For those unfamiliar these are the approved formats (at least for me
)
h9h 9h9
h9h9h9
h9h-9h9
this is what I tried to use
Should this work? Thanks
Im trying to use regular expressions to test Canadian Postal Codes. For those unfamiliar these are the approved formats (at least for me
h9h 9h9
h9h9h9
h9h-9h9
this is what I tried to use
Code: Select all
if($safeZip == "")
{
$errMsg .= "Postal Code is required. Make sure it is not left blank<br />";
}
elseif((strlen($safeZip) != 7) && (strlen($safeZip) != 6))
{
$errMsg .= "Invalid Postal Code<br />";
}
elseif(!eregi("^[a-zA-Z][0-9][a-zA-Z](\s|-)?[0-9][a-zA-Z][0-9]$", $safeZip))
{
$errMsg .= "Invalid Postal Code<br />";
}