id validator

Validate an identification number in different countries

Options

Using with form field
The HTML attributes are used to set the validator options via the Declarative plugin
(* denotes a required option)
NameHTML attributeTypeDescription
country *data-fv-id___countryString or FunctionAn ISO-3166 country code
messagedata-fv-id___messageStringThe error message
The validator supports the following countries:
CountryAbbreviation ID systemCountry code
ArgentiniaDNIAR
Bosnia and HerzegovinaJMBGBA
BrazilCPFBR
BulgariEGNBG
ChileRUN/RUTCL
ChinaRICCN
ColombiaNITCO
CroatiaOIBHR
CzechRCCZ
DenmarkCPRDK
EstoniaisikukoodEE
FinlandHETUFI
FranceNIRFR
Hong KongHKIDHK
IcelandKennitalaIS
IndiaAadhaarID
IrelandPPSIE
IsraelMispar ZehutIL
KoreaRRNKR
LatviaPersonas kodsLV
LithuaniaAsmens kodasLT
MacedoniaЕМБГMK
MalaysiaNRICMY
MexicoCURPMX
MontenegroJMBGME
NetherlandsBSNNL
NorwayFødselsnummerNO
PeruCUIPE
PolandPESELPL
RomaniaCNPRO
San Marino-SM
SerbiaJMBGRS
SlovakiaRCSK
SloveniaEMŠOSI
South AfricaSouth African IDZA
SpainDNI/NIE/CIFES
SwedenpersonnummerSE
SwitzerlandAHV-Nr/No AVSCH
Taiwan-TW
Thailand-TH
Uruguay-UY
Using the ES6 module
// You might need to change the importing path
import { id } from '/vendors/@form-validation/cjs/validator-id';
const result = id().validate({
value: ...,
options: {
// Can be a string or a function returns a string
country: ...,
message: ...,
},
});
/*
result is an object of
{
valid: true or false,
message: The error message
}
*/
Using the npm package
  • Install the validator package:
$ npm install @form-validation/validator-id
  • Use the id validator:
import { id } from '@form-validation/validator-id';
const result = id().validate({
value: ...,
options: {
// Can be a string or a function returns a string
country: ...,
message: ...,
},
});

Basic example

id validator

NPM package example

The following snippet shows how to use the id validator with the npm package:
import { id } from '@form-validation/validator-id';
const res1 = id().validate({
value: '54362315K',
options: {
country: 'ES',
message: 'The value is not a valid ID',
},
});
// res1.valid === true
const res2 = id().validate({
value: '511062-5629',
options: {
country: 'DK',
message: 'The value is not a valid ID',
},
});
// res2.valid === false

See also

Changelog

v2.1.0
  • The validator doesn't work properly if the message property isn't defined
v2.0.0
  • Add the npm package
v1.7.0
  • Fixed an issue that the South African identification validator doesn't work with the minified version
v1.6.0
  • Fixed an issue that the country option isn't passed to the placeholder message
v1.4.0
  • Separate id validators to id package to save imports when using with ES6 module
  • Support more national identification numbers, including:
  • Argentinian identification number (DNI)
  • Colombian identification number (NIT)
  • French identification number (NIR)
  • Hong Kong identification number (HKID)
  • Indian identification number (Aadhaar)
  • Korean identification number (RRN)
  • Malaysian identification number (NRCI)
  • Mexican identification number (CURP)
  • Norwegian identification number (Fødselsnummer)
  • Peruvian identification number
  • Taiwanese identification number
  • Uruguayan identification number