Package Exports
- zip-it-gb
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (zip-it-gb) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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 --saveAnd in your code:
const zipit = require('zip-it')As a bower component:
bower install zip-it --saveAnd in your page:
<script src="bower_components/zip-it/zip-it.min.js"></script> <!-- of course, you can use zip-it.js if you want to -->Simple usage
console.log(zipit.verifyCode('US', 37188)); // White house zip code
// => true
console.log(zipit.verifyCode('CA', 'H0H 0H0')); // Santa Claus's postal code
// => true
console.log(zipit.verifyCode('CN', 'Not a valid postal code'));
// => false
console.log(zipit.verifyCode('AA', 'Not a valid country code'));
// => undefinedFull API
zipit.verifyCode(countryCode, postalCode)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
postalCodeadheres 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
postalCodewill 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.isCountrySupported(countryCode)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.supportedCountryCodes()Return all supported country codes
zipit.getRegexForCountry(countryCode)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