postal-codes-js
Postal Codes
Last updated a month ago by postalcodesjs .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install postal-codes-js 
SYNC missed versions from official npm registry.

Build Status Coverage Status npm version

postal-codes.js

Provides javascript postal code validation for all countries. Supports both Node.js and web browser usage.

Validation rules

  1. Characters " " (space) and "-" (dash) are removed from the input string.
  2. Input is case insensitive.
  3. Supports both ISO 3166-1 alpha-2 and ISO 3166-1 alpha-3 country codes.
  4. Validates optional n-digit extention seperated by a space or hyphen.

Usage

const postalCodes = require('postal-codes-js');
const countryCode = 'CH'; // ISO 3166-1 alpha-2 or alpha-3 country code as string.
const postalCode = '8008'; // Postal code as string or number.
postalCodes.validate(countryCode, postalCode); // Returns 'true' if valid, error message as string otherwise.

// All the calls below returns true
postalCodes.validate('bg', '1003');
postalCodes.validate('gb', 'EC1A 1BB');
postalCodes.validate('GB', 'EC1A 1BB');
postalCodes.validate('GBR', 'EC1A 1BB');
postalCodes.validate('gb', 'EC1A1BB');
postalCodes.validate('gb', 'EC1A-1BB');
postalCodes.validate('tr', '33150');
postalCodes.validate('TR', '33150');
postalCodes.validate('TUR', '33150');
postalCodes.validate('us', '22313');
postalCodes.validate('USA', '91746-2302');

// All the calls below return a string
postalCodes.validate('UK', 'EC1A 1BB');
 > Unknown alpha2/alpha3 country code: UK

postalCodes.validate('PL', '9999');
 > Postal code 9999 is not valid for country PL

postalCodes.validate('CH');
 > Missing postal code.

Testing with mocha

$ npm test
$ npm run coverage

Contribution

Contributions are more than welcome, just fork the repo and create a pull-request ;)

Contact

PostalCodesJS@cimpress.com

Current Tags

  • 2.4.0                                ...           latest (a month ago)

19 Versions

  • 2.4.0                                ...           a month ago
  • 2.3.1                                ...           3 months ago
  • 2.3.0                                ...           3 months ago
  • 2.2.5                                ...           5 months ago
  • 2.2.4                                ...           6 months ago
  • 2.2.3                                ...           8 months ago
  • 2.2.2                                ...           8 months ago
  • 2.2.1                                ...           9 months ago
  • 2.2.0                                ...           9 months ago
  • 2.1.0                                ...           10 months ago
  • 2.0.2                                ...           a year ago
  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.0.4                                ...           2 years ago
  • 0.0.3                                ...           2 years ago
  • 0.0.2                                ...           4 years ago
  • 0.0.1                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 48
Dependencies (2)
Dev Dependencies (4)

Copyright 2014 - 2016 © taobao.org |