Validate Postal Code Script

Validate Postal Code Script is use to validate the format of a postal ("zip") code.

Demo :



  Validate a zip :    

Example :

Just type a proper postal code number like this 123456 and click check button Is a properly-formatted zip code message will display otherwise type a 56456 number at textbox and click check button Is an improperly-formatted zip code will display here.

Code :

Following code is use to Validate Postal Code Script if you need to copy and use to your website.


<?php
  function validateZip($str)
  {
    return preg_match("/^\d{6}$/" ,$str);
  }
    $postal_code = "123456";
    echo validateZip($postal_code) ? "Is a properly-formatted zip code" : "Is an improperly-formatted zip code";
?>

In the above $postal_code variable is use to assign the postal code number. In the validateZip() function is use to check the validate postal code number through regular expression.

Free Download Script :

If you need validate postal code script click and download from following link.

Download




Content