Skip to content

A library for verifying Nordic personal identification numbers with accuracy and ease.

License

Notifications You must be signed in to change notification settings

FiiveAB/nordic-id-validator

Repository files navigation

Nordic ID Validator

Nordic-ID-Validator is a comprehensive toolkit for verifying Nordic personal identification numbers with accuracy and ease.

Features

  • Supports all major Nordic countries: Sweden, Norway, Denmark, and Finland.
  • Provides both format and date validation.
  • Lightweight with no external dependencies.

Installation

Using npm:

npm install nordic-id-validator

Usage

First, import the Validator class:

const Validator = require('nordic-id-validator');

Next, create an instance of the Validator class:

const validator = new Validator();

To validate a personal number, use the isValid method by passing the personal number and the respective country code:

const isValid = validator.isValid('your_personal_number', 'SE'); // For Swedish numbers

Replace 'your_personal_number' with the personal number you want to validate and 'SE' with the respective country code. Valid country codes are:

  • SE for Sweden
  • NO for Norway
  • DK for Denmark
  • FI for Finland

Example:

const isValidSwedish = validator.isValid('123456-7890', 'SE');
console.log(isValidSwedish); // true or false based on the validity

const isValidNorwegian = validator.isValid('12345678901', 'NO');
console.log(isValidNorwegian); // true or false based on the validity

You can also validate a personal number without specifying the country code. In this case, the country is specified by the the function. For example:

const isValidSwedish = validator.isValidSE('123456-7890');
console.log(isValidSwedish); // true or false based on the validity

The following country-specific methods are available:

  • isValidSE for Swedish SSN
  • isValidNO for Norwegian SSN
  • isValidDK for Danish SSN
  • isValidFI for Finnish SSN

Error Handling

The isValid method will throw an error if an invalid country code is provided or if the input is neither a string nor a number:

try {
    const isValid = validator.isValid('your_personal_number', 'INVALID_COUNTRY_CODE');
} catch (error) {
    console.error(error.message);
}

Contribution

We welcome contributions! If you find a bug or have suggestions, please open an issue.

License

MIT

A project by Fiive.

About

A library for verifying Nordic personal identification numbers with accuracy and ease.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published