FormValidation v0.8.1 is released, supports Bootstrap 4 alpha 3

id validator

Validate identification number

Validators

Options

* — Required option

Option HTML attribute Type Description
country* data-fv-id-country String An ISO-3166 country code.
It's dynamic option
message data-fv-id-message String The error message. The dynamic message is supported
When setting options via HTML attributes, remember to enable the validator by setting data-fv-id="true".
The message and other options can be updated on the fly via the updateMessage() and updateOption() methods

The validator supports the following countries (click the sample number to validate it):

No. Country Abbreviation ID system Country code Example
1 Bosnia and Herzegovina JMBG BA
2 Brazil CPF BR
3 Bulgari EGN BG
4 Chile RUN/RUT CL
5 China CN
6 Croatia OIB HR
7 Czech RC CZ
8 Denmark CPR DK
9 Estonia isikukood EE
10 Finland HETU FI
11 Iceland Kennitala IS
12 Ireland PPS IE
13 Latvia Personas kods LV
14 Lithuania Asmens kodas LT
15 Macedonia ЕМБГ MK
16 Montenegro JMBG ME
17 Netherlands BSN NL
18 Poland PESEL PL
19 Romania CNP RO
20 San Marino SM
21 Serbia JMBG RS
22 Slovakia RC SK
23 Slovenia EMŠO SI
24 South Africa South African ID ZA
25 Spain DNI/NIE/CIF ES
26 Sweden personnummer SE
27 Switzerland AHV-Nr/No AVS CH
28 Thailand TH

Example

<form id="idForm" class="form-horizontal">
    <div class="form-group">
        <label class="col-xs-3 control-label">Country</label>
        <div class="col-xs-5">
            <select class="form-control" name="countrySelectBox">
                <option value="BA">Bosnia and Herzegovina</option>
                <option value="BR">Brazil</option>
                <option value="BG">Bulgari</option>
                <option value="CL">Chile</option>
                <option value="CN">China</option>
                <option value="HR">Croatia</option>
                <option value="CZ">Czech</option>
                <option value="DK">Denmark</option>
                <option value="EE">Estonia</option>
                <option value="FI">Finland</option>
                <option value="IS">Iceland</option>
                <option value="IE">Ireland</option>
                <option value="LV">Latvia</option>
                <option value="LT">Lithuania</option>
                <option value="MK">Macedonia</option>
                <option value="ME">Montenegro</option>
                <option value="NL">Netherlands</option>
                <option value="PL">Poland</option>
                <option value="RO">Romania</option>
                <option value="SM">San Marino</option>
                <option value="RS">Serbia</option>
                <option value="SK">Slovakia</option>
                <option value="SI">Slovenia</option>
                <option value="ZA">South Africa</option>
                <option value="ES">Spain</option>
                <option value="SE">Sweden</option>
                <option value="CH">Switzerland</option>
                <option value="TH">Thailand</option>
            </select>
        </div>
    </div>

    <div class="form-group">
        <label class="col-xs-3 control-label">ID number</label>
        <div class="col-xs-5">
            <input type="text" class="form-control" name="idNumber" />
        </div>
    </div>
</form>

<script>
$(document).ready(function() {
    $('#idForm')
        .formValidation({
            framework: 'bootstrap',
            icon: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                idNumber: {
                    validators: {
                        id: {
                            country: 'countrySelectBox',
                            message: 'The value is not valid %s ID'
                        }
                    }
                }
            }
        })
        // Revalidate ID number when changing the country
        .on('change', '[name="countrySelectBox"]', function(e) {
            $('#idForm').formValidation('revalidateField', 'idNumber');
        });
});
</script>
<form id="idForm" class="form-horizontal"
    data-fv-framework="bootstrap"
    data-fv-icon-valid="glyphicon glyphicon-ok"
    data-fv-icon-invalid="glyphicon glyphicon-remove"
    data-fv-icon-validating="glyphicon glyphicon-refresh">

    <div class="form-group">
        <label class="col-xs-3 control-label">Country</label>
        <div class="col-xs-6">
            <select class="form-control" name="countrySelectBox">
                <option value="BA">Bosnia and Herzegovina</option>
                <option value="BR">Brazil</option>
                <option value="BG">Bulgari</option>
                <option value="CL">Chile</option>
                <option value="CN">China</option>
                <option value="HR">Croatia</option>
                <option value="CZ">Czech</option>
                <option value="DK">Denmark</option>
                <option value="EE">Estonia</option>
                <option value="FI">Finland</option>
                <option value="IS">Iceland</option>
                <option value="IE">Ireland</option>
                <option value="LV">Latvia</option>
                <option value="LT">Lithuania</option>
                <option value="MK">Macedonia</option>
                <option value="ME">Montenegro</option>
                <option value="NL">Netherlands</option>
                <option value="PL">Poland</option>
                <option value="RO">Romania</option>
                <option value="SM">San Marino</option>
                <option value="RS">Serbia</option>
                <option value="SK">Slovakia</option>
                <option value="SI">Slovenia</option>
                <option value="ZA">South Africa</option>
                <option value="ES">Spain</option>
                <option value="SE">Sweden</option>
                <option value="CH">Switzerland</option>
                <option value="TH">Thailand</option>
            </select>
        </div>
    </div>

    <div class="form-group">
        <label class="col-xs-3 control-label">ID number</label>
        <div class="col-xs-6">
            <input type="text" class="form-control" name="idNumber"
                data-fv-id="true"
                data-fv-id-country="countrySelectBox"
                data-fv-id-message="The value is not valid %s ID" />
        </div>
    </div>
</form>

<script>
$(document).ready(function() {
    $('#idForm')
        .formValidation()
        // Revalidate ID number when changing the country
        .on('change', '[name="countrySelectBox"]', function(e) {
            $('#idForm').formValidation('revalidateField', 'idNumber');
        });
});
</script>

Related validators

The following validators might be useful to you: