US Zip Code Validation Script

US Zip Code Validation Script is use to validate a US zip (postal) code at here.

Demo :



  Validate Us zip :    

Example :

Just type a validate US zip code like this 10113-1243 and click check button Is a properly-formatted US zip code message will display otherwise type a 56456 number at textbox and click check button Is an improperly-formatted US zip code will display here.

Code :

Following code is use to US Zip Code Validation Script if you need to copy and use to your website.


<?php
  function validateUSZip($str)
  {
    return preg_match("/^\d{5}(-\d{4})?$/" ,$str);
  }
  $us_zip_code = "10113-1243";
  echo validateUSZip($us_zip_code) ? "Is a properly-formatted US zip code" : "Is an improperly-formatted US zip code";
?>

In the above $us_zip_code variable is use to assign the zip code number. In the validateUSZip() function is use to check the validate zip code number through regular expression.

Free Download Script :

If you need to us zip code validation script click and download from following link.

Download




Content