id validator

Validate an identification number

Options

Using with form field

* presents a required option. The HTML attributes are used to set the validator options via the Declarative plugin

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 (click the sample number to validate it):

# Country Abbreviation ID system Country code Sample ID Is it valid?
1 Argentinia DNI AR undefined
2 Bosnia and Herzegovina JMBG BA undefined
3 Brazil CPF BR undefined
4 Bulgari EGN BG undefined
5 Chile RUN/RUT CL undefined
6 China RIC CN undefined
7 Colombia NIT CO undefined
8 Croatia OIB HR undefined
9 Czech RC CZ undefined
10 Denmark CPR DK undefined
11 Estonia isikukood EE undefined
12 Finland HETU FI undefined
13 France NIR FR undefined
14 Hong Kong HKID HK undefined
15 Iceland Kennitala IS undefined
16 India Aadhaar ID undefined
17 Ireland PPS IE undefined
18 Korea RRN KR undefined
19 Latvia Personas kods LV undefined
20 Lithuania Asmens kodas LT undefined
21 Macedonia ЕМБГ MK undefined
22 Malaysia NRIC MY undefined
23 Mexico CURP MX undefined
24 Montenegro JMBG ME undefined
25 Netherlands BSN NL undefined
26 Norway Fødselsnummer NO undefined
27 Peru CUI PE undefined
28 Poland PESEL PL undefined
29 Romania CNP RO undefined
30 San Marino - SM undefined
31 Serbia JMBG RS undefined
32 Slovakia RC SK undefined
33 Slovenia EMŠO SI undefined
34 South Africa South African ID ZA undefined
35 Spain DNI/NIE/CIF ES undefined
36 Sweden personnummer SE undefined
37 Switzerland AHV-Nr/No AVS CH undefined
38 Taiwan - TW undefined
39 Thailand - TH undefined
40 Uruguay - UY undefined

Using with JavaScript module


// You might need to change the importing path
import id from 'formvalidation/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

You can click on sample from the table above to see if it's a valid or invalid id.

Module Example

The following snippet shows how to use the id validator with JavaScript module:


// You might need to change the importing path
import id from 'formvalidation/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

Related validators

The following validators are similar to this one and might be useful to you.

Name Description
vat Validate VAT number