Skip to content

mikaello/norwegian-national-id-validator

Repository files navigation

norwegian-national-id-validator

Travis build status npm

Validate Norwegian national identity numbers (birth number (fødselsnummer), D-number, H-number and FH-number).

The NPM module is ES5, but TypeScript and Flow types is also exported. Types for Flow is generated with Flowgen.

Installation

Install the package via npm:

npm install --save norwegian-national-id-validator

or

yarn add norwegian-national-id-validator

Usage

This package exports a functional and object-oriented API for your convenience.

Object-oriented API

import { NorwegianId } from 'norwegian-national-id-validator';

const validation = NorwegianId('29029600013');

console.log(validation.isValid())
// => true

console.log(validation.isBirthNumber())
// => true

console.log(validation.isDNumber())
// => false

console.log(validation.isHNumber())
// => false

console.log(validation.isFhNumber())
// => false

console.log(validation.isMale())
// => false

console.log(validation.isFemale())
// => true

console.log(validation.age())
// => 24

console.log(validation.birthDate())
// => Thu Feb 29 1996 [...]

Functional API

validateNorwegianIdNumber(value)

This function checks if the given value is a valid Norwegian national identity number. Returns true for valid, and false for invalid ID-number.

Examples

import { validateNorwegianIdNumber } from 'norwegian-national-id-validator';

validateNorwegianIdNumber('29029900157');
// => false

validateNorwegianIdNumber('29029600013');
// => true

possibleAgeOfPersonWithIdNumber(value)

This function returns the age of a person with given Norwegian national identity number.

Returns undefined when birth date could not be determined (e.g. for FH-numbers and invalid ID-numbers).

Examples

import { possibleAgeOfPersonWithIdNumber } from 'norwegian-national-id-validator';

possibleAgeOfPersonWithIdNumber('03111590925');
// => 1

possibleAgeOfPersonWithIdNumber('03110175225');
// => 15

Documentation

Apart from this README, you can find details and examples of using the SDK in the following places:

Tests

To run the tests for this module:

npm test

Other relevant projects

License

MIT