Satyendra Mishra Satyendra Mishra - 1 year ago 107
Javascript Question

Zipcode validation for US

Can any one tell me how can i validate zipcode for US using regular expression.

I used below expression for validation

var us_postcode_regular = /^([0-9]{5})(?:[-\s]*([0-9]{4}))?$/;

However it is not able to validate all 00000 or 11111 or similar numbers.

and how can i validate the incorrect zipcode like the five digits which are not the part of US zipcode.

Answer Source
if(ctype_digit($zip) && strlen($zip) == 5){ echo 'US Zip Code'; }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download