PHP (RegEx) Zip Code Validation


/ Published in: PHP
Save to your folder(s)

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


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

URL: http://www.thejwalker.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.