pt-id-validator
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

PT-ID-Validator

npm

This library provides functions to validate the portuguese Bilhete de Identidade and Cartão de Cidadão number.

Usage

The module is available in npm.

In order to perform validations, you need to input the ID number accordingly to the description in the documentation provided by the portuguese government (Portuguese only). Although this description is for Cartão de Cidadão, the same applies for Bilhete de Identidade, only without the AAT end.

The provided function checks the correctness of the number and the format.

check(val) verifies if the format is valid for either Cartão do Cidadão or Bilhete de Identidade, according to the format DDDDDDDD C AAT or DDDDDDDD C, respectively. After that, it uses the correct check digit algorithm to verify if it the number is valid.

If the number that you want to check has 7 digits instead of 8, you don't need to input the leftmost 0 of the number.

The return values are as follows:

  • false if the provided string is not a valid Cartão do Cidadão/Bilhete de Identidade
  • true if the provided string is a valid Cartão do Cidadão/Bilhete de Identidade

When an incorrect format is passed, a TypeError is thrown.

Readme

Keywords

Package Sidebar

Install

npm i pt-id-validator

Weekly Downloads

3

Version

2.0.1

License

MIT

Unpacked Size

7.01 kB

Total Files

5

Last publish

Collaborators

  • afonsofgarcia