Pages

Saturday, February 28, 2009

Validate ZIP in Java Script

Check out the below code to validate zip code.
NOTE: This code is use to validate the Zip Codes in US region only or any Postal code which contains the following format:
nnnnn-nnnn

function ValidateZip(s)
{
reZip = new RegExp(/(^\d{5}$)(^\d{5}-\d{4}$)/);
if (!reZip.test(s))
{
alert("Zip Code Is In-Valid");
return false;
}
return true;

}

No comments: