https://github.com/fiiveab/nordic-id-validator
A library for verifying Nordic personal identification numbers with accuracy and ease.
https://github.com/fiiveab/nordic-id-validator
social-security-number ssn-validation validator
Last synced: 3 months ago
JSON representation
A library for verifying Nordic personal identification numbers with accuracy and ease.
- Host: GitHub
- URL: https://github.com/fiiveab/nordic-id-validator
- Owner: FiiveAB
- License: mit
- Created: 2023-10-10T09:01:14.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-11T17:45:02.000Z (about 1 year ago)
- Last Synced: 2025-02-17T02:04:04.032Z (3 months ago)
- Topics: social-security-number, ssn-validation, validator
- Language: JavaScript
- Homepage:
- Size: 230 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:
```bash
npm install nordic-id-validator```
## Usage
First, import the Validator class:
```jsx
const Validator = require('nordic-id-validator');```
Next, create an instance of the Validator class:
```jsx
const validator = new Validator();```
To validate a personal number, use the **`isValid`** method by passing the personal number and the respective country code:
```jsx
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 FinlandExample:
```jsx
const isValidSwedish = validator.isValid('123456-7890', 'SE');
console.log(isValidSwedish); // true or false based on the validityconst 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:
```jsx
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:
```jsx
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](https://www.fiive.se).