I've built two PHP 4.3 functions, both of which work, to validate zip codes. The first is for validating a regular 5 digit code :
if (preg_match ('/[0-9]{5}$/', $zipcode))
This one is for 9 digit codes :
if ( preg_match ( '/([0-9]{5})-([0-9]{4})$/', $zipcode) )
Now I wanted to validate either type (depending upon what the user types in) by "OR-ing" both expressions as :
if ( preg_match ( ('/([0-9]{5})$/') | ('/([0-9]{5})-([0-9]{4})$/'), $zipcode) )
but the compiler keeps returning a Warning: Unknown modifier '[' in function error, and the function does not work!
If I remove the inner parens around the second expression, the erro goes away, but the function still does not work (it rejects both "12345" and "12345-6789" types :
if ( preg_match ( ('/([0-9]{5})$/') | ('/[0-9]{5})-([0-9]{4}$/'), $zipcode) )
It seems like I cannot use the OR operator here for some reason to check both types of zipcodes. This one has got me pulling my hair out to the point that I'm about ready to use the first two functions, and then call the appropriate one, depending upon how many chars the user types in. 🙁