pv
postcode-validator
npm i postcode-validator
pv

postcode-validator

Validate postcodes based on country

by Melwyn Furtado

3.6.6 (see all)License:MITTypeScript:Not Found
npm i postcode-validator
Readme

postcode-validator

Commitizen friendly

Node.js module for parsing and validating postcodes. Country specific validation is supported for most countries including GB, US, Canada, Japan and many others.

Note: I haven't tested all combinations of postcodes for the extended country regular expressions. Please raise a PR with necessary test coverage for as many countries possible.

Install

npm install postcode-validator

Usage

// commonjs
const { postcodeValidator, postcodeValidatorExistsForCountry } = require('postcode-validator');
// ES6
import { postcodeValidator, postcodeValidatorExistsForCountry } from 'postcode-validator';

postcodeValidator('W85TT', 'GB'); // returns true
postcodeValidator('1234567', 'GB'); // returns false

postcodeValidatorExistsForCountry('GB'); // returns true
postcodeValidatorExistsForCountry('Moon'); // returns false

country codes: US, GB, CA, JP, INTL(International), etc

Testing

Run the unit tests with:

npm test

Conventional Commits

Commit code using below npm script or just follow conventional commits for commit messages using git commit.

npm run commit

Downloads/wk

17.2K

GitHub Stars

48

LAST COMMIT

2mos ago

MAINTAINERS

1

CONTRIBUTORS

15

OPEN ISSUES

1

OPEN PRs

0
VersionTagPublished
3.6.6
latest
2mos ago
No alternatives found
No tutorials found
Add a tutorial