Posted By

aristoworks on 07/01/08


Tagged

php code validation regular expressions zip


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

jdstraughan
robe
rb
ddavidd


PHP (RegEx) Zip Code Validation


 / Published in: PHP
 

URL: http://www.thejwalker.com

This is a simple method of validating a 9-digit zip code using PHP and regular expressions

  1. $string = "12345-1234";
  2. if (preg_match('/^[0-9]{5}([- ]?[0-9]{4})?$/', $string)) {
  3. echo "zip code checks out";
  4. }

Report this snippet  

You need to login to post a comment.