Free postal code validation for the web.
- Validates against expected regex patterns of the country.
- Looks up the code via a CDN for accurate validation and geographical data.
<script src="https://cdn.jsdelivr.net/gh/zipcodes/zipcodes.js@1/zipcodes.min.js"></script>
getZipCode('US', '90210', function (result) {
console.log(result);
});
Output:
{
"input":{
"country": "US",
"zip": "90210"
},
"lookup":{
"countryCode": "US",
"postalCode": "90210",
"placeName": "Beverly Hills",
"adminName1": "California",
"adminCode1": "CA",
"adminName2": "Los Angeles",
"adminCode2": "037",
"adminName3": "",
"adminCode3": "",
"latitude": "34.0901",
"longitude": "-118.4065",
"accuracy": "4"
},
"pattern": /^\d{5}(-\d{4})?$/,
"validPattern": true,
"validLookup": true,
"valid": true
}
Country codes should follow ISO 3166-1 alpha-2
- Some patterns borrowed from https://github.com/sarcadass/i18n-zipcodes
- Zipcode database from http://download.geonames.org