views:

23

answers:

1

Hello SO:

I am a bit rusty at PHP, so bear with me. I am making a simple email form that validates a few key pieces of data. One of these fields is the submitter's zip code. To validate this, I figured a regex would be simple since I am pretty confident the validation can be done in one line. Behold:

preg_match("^([0-9]{5}|[0-9]{5}\-[0-9]{4})$", $zip);

This should be working to match 12345 and 12345-6789. However, this does not happen. What am I overlooking here?

Thanks!

+5  A: 

Missing delimiters:

preg_match("/^([0-9]{5}|[0-9]{5}\-[0-9]{4})$/", $zip);
Sarfraz
Apparently so. Delimiters always mess with me in PHP. Thanks for the quick response :)
Anders
@Anders: You are welcome....
Sarfraz