note 57459 deleted from function.ereg by tularis
| From: | tularis@php.net | Date: | Thu, 31 May 2007 13:23:38 +0000 |
| Subject: | note 57459 deleted from function.ereg by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127065@lists.php.net to get a copy of this message | ||
Note Submitter: mcallier at gmail dot com
----
I think that fox's zip code check may need a slight modification. Here is fox's code:
$error_code=(ereg("^[0-9]{5}(-[0-9]{4})$",$zip))? NULL:1;
This will error on valid zipcodes such as 99212. If you change the regular expression to:
$error_code=(ereg("^[0-9]{5}(-[0-9]{4})*$",$zip))? NULL:1;
It will not error on valid zipcodes such as 99212.
To test this you may use the following code:
<?php
$testzip[]="99212";
$testzip[]="9921";
$testzip[]="99212-1234";
$testzip[]="9921a";
$testzip[]="99212-12";
$regex['fox']="^[0-9]{5}(-[0-9]{4})$";
$regex['mcallier']="^[0-9]{5}(-[0-9]{4})*$";
foreach($regex as $key=>$expression)
{
echo($key."<br>\n");
echo("-----------<br>\n");
foreach($testzip as $value)
{
$test=ereg($expression,$value);
$test==1?$test="good":$test="bad";
echo("$value=$test<br>\n");
}
echo("<br>\n");
}
?>
The output of this is:
fox
-----------
99212=bad
9921=bad
99212-1234=good
9921a=bad
99212-12=bad
mcallier
-----------
99212=good
9921=bad
99212-1234=good
9921a=bad
99212-12=bad