id validator
Validate an identification number in different countries
Options
Using with form field
(* 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
import id from 'formvalidation/dist/es6/validators/id';
const result = id().validate({
value: ...,
options: {
country: ...,
message: ...,
},
});
Basic example
ES6 Module Example
The following snippet shows how to use the id validator with ES6 module:
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',
},
});
const res2 = id().validate({
value: '511062-5629',
options: {
country: 'DK',
message: 'The value is not a valid ID',
},
});
See also
Changelog
- Fixed an issue that the South African identification validator doesn't work with the minified version
- Fixed an issue that the
country option isn't passed to the placeholder message
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