Getting Started

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)
Name HTML attribute Type Description
country * data-fv-id___country String or Function An ISO-3166 country code
message data-fv-id___message String The error message
The validator supports the following countries:
Country Abbreviation ID system Country code
Argentinia DNI AR
Bosnia and Herzegovina JMBG BA
Brazil CPF BR
Bulgari EGN BG
Chile RUN/RUT CL
China RIC CN
Colombia NIT CO
Croatia OIB HR
Czech RC CZ
Denmark CPR DK
Estonia isikukood EE
Finland HETU FI
France NIR FR
Hong Kong HKID HK
Iceland Kennitala IS
India Aadhaar ID
Ireland PPS IE
Israel Mispar Zehut IL
Korea RRN KR
Latvia Personas kods LV
Lithuania Asmens kodas LT
Macedonia ЕМБГ MK
Malaysia NRIC MY
Mexico CURP MX
Montenegro JMBG ME
Netherlands BSN NL
Norway Fødselsnummer NO
Peru CUI PE
Poland PESEL PL
Romania CNP RO
San Marino - SM
Serbia JMBG RS
Slovakia RC SK
Slovenia EMŠO SI
South Africa South African ID ZA
Spain DNI/NIE/CIF ES
Sweden personnummer SE
Switzerland AHV-Nr/No AVS CH
Taiwan - TW
Thailand - TH
Uruguay - UY
Using with ES6 module
            
// You might need to change the importing path
import id from 'formvalidation/dist/es6/validators/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
}
*/

Basic example

id validator

ES6 Module Example

The following snippet shows how to use the id validator with ES6 module:
            
// You might need to change the importing path
import id from 'formvalidation/dist/es6/validators/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

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