Friday, July 3, 2009

Validation of US Zip Code

The following Java Script validates the US Zip Code.

It validates the US Zip Code which Should be in 5 digit Format or Zip + 4 Format.


/*This function accepts String as Parameter: Zip code to be validated */

/*This function returns True if valid other wise false */



function funcValidateUSZip( strValue ) {

var MyRegExp = /(^\d{5}$)|(^\d{5}-\d{4}$)/;

//check for valid US Zipcode
return MyRegExp.test(strValue);
}




funcValidateUSZip('44094') - returns true
funcValidateUSZip('99999-9999') returns true

funcValidateUSZip('4402') returns false
funcValidateUSZip('44094-999') returns false

No comments:

Post a Comment