Validate national id numbers for people and organizations in different countries
npm install validate-ninvalidate-nin consists of pure functions to validate and normalize national identity numbers of people and/or organizations in
countries that use such well-recognized identity number systems.
$ npm install validate-nin --save
`Usage
This example shows you how to validate Swedish Nin's ("Personnummer").
`js
const validateNin = require('validate-nin');
let swedishPersonValidator = validateNin.getValidator({ country: 'se', type: 'person'});
let okResult = swedishPersonValidator.isValidNiN("811218-9876"); // -> true
let notOkResult = swedishPersonValidator.isValidNiN("811218-9877"); // -> false
let normalized = swedishPersonValidator.normalizeNin("811218-9876"); // -> 8112189876
let formatted = swedishPersonValidator.format("8112189876"); // -> 811218-9876
`Contribute
You can easily extend validate-nin with additional validators for (country, type) tuples in the following manner
`js
validateNin.addValidator({
country: 'xx', // ISO 3166-1 alpha-2 code
type: 'yy', // Either "person" or "organization"
isValidNinFn: nin => { / return true if valid / },
normalizeNin: nin => { / return normalized form / }
});
`We encourage you to put the argument of
addValidator as a module export in a js file in an appropriate location within the validators` directory of this repository and create a pull request.