Validate zip codes countrywise
npm install @calilio-global/zip-validator
Node.js module for parsing and validating zipCodes. Country specific validation is supported for most countries.
Note: I haven't tested all combinations of zipCodes for the extended country regular expressions. Please raise a PR with necessary test coverage for as many countries possible.
``javascript`
npm install @calilio-global/zip-validator
`javascript
// commonjs
const { zipCodeValidator, zipCodeValidatorExistsForCountry } = require('@calilio-global/zip-validator');
// ES6
import { zipCodeValidator, zipCodeValidatorExistsForCountry } from '@calilio-global/zip-validator';
zipCodeValidator('W85TT', 'GB'); // returns true
zipCodeValidator('1234567', 'GB'); // returns false
zipCodeValidatorExistsForCountry('GB'); // returns true
zipCodeValidatorExistsForCountry('Moon'); // returns false
country codes: US, GB, CA, JP, INTL(International), etc
`
Run the unit tests with:
`javascript`
npm test
`javascript`
[
'AE', 'AG', 'AO', 'AQ', 'AW', 'BF', 'BI', 'BJ',
'BO', 'BQ', 'BS', 'BV', 'BW', 'BZ', 'CD', 'CF',
'CG', 'CI', 'CM', 'CW', 'DJ', 'DM', 'ER', 'FJ',
'GA', 'GD', 'GH', 'GM', 'GQ', 'GY', 'HK', 'JM',
'KI', 'KM', 'KN', 'KP', 'LC', 'LY', 'ML', 'MO',
'MR', 'MS', 'MW', 'NR', 'NU', 'PS', 'QA', 'RW',
'SB', 'SC', 'SL', 'SR', 'SS', 'ST', 'SX', 'SY',
'TD', 'TF', 'TG', 'TK', 'TL', 'TO', 'TT', 'TV',
'UG', 'VU', 'WS', 'YE', 'ZW'
]
javascript
"main": "dist/index.js",
``