note 57459 added to function.ereg
| From: | mcallier at gmail dot com | Date: | Tue, 04 Oct 2005 20:21:20 +0000 |
| Subject: | note 57459 added to function.ereg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96391@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.ereg.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57459
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57459&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57459&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57459&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57459&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57459&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57459&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57459&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57459&report=yes
Search -- http://master.php.net/manage/user-notes.php