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

vat validator

Validate VAT number

Validators

Options

Option HTML attribute Type Description
country data-fv-vat-country String An ISO-3166 country code.
It's dynamic option.
If it is not defined, it will be parsed from the VAT number
message data-fv-vat-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-vat="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 example VAT number to validate it):

No. Country Abbreviation VAT name Country code Example
1 Austria UID AT
2 Belgium n° TVA / BTW-nr / Mwst-nr BE
3 Brazil CNPJ BR
4 Bulgaria ДДС номер BG
5 Croatia PDV-ID; OIB HR
6 Cyprus ΦΠΑ CY
7 Czech Republic DIČ CZ
8 Denmark CVR DK
9 Estonia KMKR EE
10 Finland ALV nro FI
11 France n° TVA FR
12 Germany USt-IdNr. DE
13 Greece ΑΦΜ GR / EL
14 Hungary ANUM HU
15 Iceland VSK IS
16 Ireland VAT no IE
17 Italy P.IVA IT
18 Latvia PVN LV
19 Lithuania PVM kodas LT
20 Luxembourg No. TVA LU
21 Malta Vat No. MT
22 Netherlands Btw-nr. NL
23 Norway Orgnr NO
24 Poland NIP PL
25 Portugal NIF / NIPC PT
26 Romania CIF RO
27 Russia ИНН RU
28 Serbia PIB RS
29 Slovakia IČ DPH SK
30 Slovenia ID za DDV SI
31 South Africa ZA
32 Spain NIF / CIF ES
33 Sweden Momsnr. SE
34 Switzerland MWST / TVA / IVA CH
35 United Kingdom VAT Reg No GB
36 Venezuela RIF VE

Example

<form id="vatForm" 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="AT">Austria</option>
                <option value="BE">Belgium</option>
                <option value="BR">Brazil</option>
                <option value="BG">Bulgaria</option>
                <option value="HR">Croatia</option>
                <option value="CY">Cyprus</option>
                <option value="CZ">Czech Republic</option>
                <option value="DK">Denmark</option>
                <option value="EE">Estonia</option>
                <option value="FI">Finland</option>
                <option value="FR">France</option>
                <option value="DE">Germany</option>
                <option value="GR">Greece</option>
                <option value="HU">Hungary</option>
                <option value="IS">Iceland</option>
                <option value="IE">Ireland</option>
                <option value="IT">Italy</option>
                <option value="LV">Latvia</option>
                <option value="LT">Lithuania</option>
                <option value="LU">Luxembourg</option>
                <option value="MT">Malta</option>
                <option value="NL">Netherlands</option>
                <option value="NO">Norway</option>
                <option value="PL">Poland</option>
                <option value="PT">Portugal</option>
                <option value="RO">Romania</option>
                <option value="RU">Russia</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="GB">United Kingdom</option>
                <option value="VE">Venezuela</option>
            </select>
        </div>
    </div>

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

<script>
$(document).ready(function() {
    $('#vatForm')
        .formValidation({
            framework: 'bootstrap',
            icon: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                vat: {
                    validators: {
                        vat: {
                            country: 'countrySelectBox',
                            message: 'The VAT number is not valid'
                        }
                    }
                }
            }
        })
        // Revalidate the vat number when changing the country
        .on('change', '[name="countrySelectBox"]', function(e) {
            $('#vatForm').formValidation('revalidateField', 'vat');
        });
});
</script>
<form id="vatForm" 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-5">
            <select class="form-control" name="countrySelectBox">
                <option value="AT">Austria</option>
                <option value="BE">Belgium</option>
                <option value="BR">Brazil</option>
                <option value="BG">Bulgaria</option>
                <option value="HR">Croatia</option>
                <option value="CY">Cyprus</option>
                <option value="CZ">Czech Republic</option>
                <option value="DK">Denmark</option>
                <option value="EE">Estonia</option>
                <option value="FI">Finland</option>
                <option value="FR">France</option>
                <option value="DE">Germany</option>
                <option value="GR">Greece</option>
                <option value="HU">Hungary</option>
                <option value="IS">Iceland</option>
                <option value="IE">Ireland</option>
                <option value="IT">Italy</option>
                <option value="LV">Latvia</option>
                <option value="LT">Lithuania</option>
                <option value="LU">Luxembourg</option>
                <option value="MT">Malta</option>
                <option value="NL">Netherlands</option>
                <option value="NO">Norway</option>
                <option value="PL">Poland</option>
                <option value="PT">Portugal</option>
                <option value="RO">Romania</option>
                <option value="RU">Russia</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="GB">United Kingdom</option>
                <option value="VE">Venezuela</option>
            </select>
        </div>
    </div>

    <div class="form-group">
        <label class="col-xs-3 control-label">VAT number</label>
        <div class="col-xs-5">
            <input type="text" class="form-control" name="vat"
                data-fv-vat="true"
                data-fv-vat-country="countrySelectBox"
                data-fv-vat-message="The VAT number is not valid" />
        </div>
    </div>
</form>

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

Related validators

The following validators might be useful to you: