I was just wondering.. when you are using a regular expression to check the format of a zip code, would you not want to include the carrot () to start the expression and use the $ at the end?
Currently, you have:
$zip='([a-z0-9][0-9][a-z0-9][- ]*[0-9][a-z0-9][0-9]*)([- ]+([0-9]{4}))*';
Would it not be better to use? :
$zip='(^[a-z0-9][0-9][a-z0-9][- ]*[0-9][a-z0-9][0-9]*)([- ]+([0-9]{4}))*$';
I could be wrong.. but doesn't the current code mean someone can add characters before / after the conditions set and go by undetected?
One other thing to note... in this line:
if($plus4=$a[4])$zipplus4=$zip.'-'.$plus4;
Are you checking if the variable $plus4 is equal to $a[4]?
Because with this line, you are indeed assigning $plus4 to equal $a[4] (which will always result in being true.
otherwise, it should be:
if($plus4 == $a[4]) $zipplus4 = $zip.'-'.$plus4;
Lasty, this looks incorrect:
isset($$v)?$b[$v]=$$v:'';
You have a few dollar signs too many I think 😉
Cheers,
NRG