zip-it
A small library that helps you to verify postal (zip) codes from around the globe
Installation
As a node package:
npm install zip-it --save
And in your code:
const zipit =
As a bower component:
bower install zip-it --save
And in your page:
<!-- of course, you can use zip-it.js if you want to -->
Simple usage
console; // White house zip code// => trueconsole; // Santa Claus's postal code// => trueconsole;// => falseconsole;// => undefined
Full API
zipit
Returns true
if postalCode
is a valid postal code in the country, false
if it's invalid or undefined
if countryCode
is not a valid country code
Notes:
- The verification is not done on the exact address, but verifies
postalCode
adheres to the format of the postal code in the given country. - Many countries (66 to be exact) don't have a postal code of any sort. In that case, any value of
postalCode
will returntrue
.
Arguments
countryCode
(String) – a two capital letters string, representing the relevant country according to iso 3166-2postalCode
(String|Number) – the postal code to verify
zipit
Returns true
if countryCode
is supported, false
otherwise.
Currently zip-it suppports all 234 countries I was able to find in Wikipedia, so if isCountrySupported
returns false
, there's a good chance the code is invalid.
Arguments
countryCode
(String) – a two capital letters string, representing the relevant country according to iso 3166-2
zipit
Return all supported country codes
zipit
Returns the regular expression used for that country. Can be useful in a pattern
attribute of an <input>
tag
Arguments
countryCode
(String) – a two capital letters string, representing the relevant country according to iso 3166-2