vat validator

Validate VAT numbers 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)
NameHTML attributeTypeDescription
country *data-fv-vat___countryString or FunctionAn ISO-3166 country code
messagedata-fv-vat___messageStringThe error message
The validator supports the following countries:
CountryAbbreviation VAT systemCountry code
Argentina-AR
AustriaUIDAT
Belgiumn° TVA / BTW-nr / Mwst-nrBE
BrazilCNPJBR
BulgariaДДС номерBG
CroatiaPDV-ID; OIBHR
CyprusΦΠΑCY
Czech RepublicDIČCZ
DenmarkCVRDK
EstoniaKMKREE
FinlandALV nroFI
Francen° TVAFR
GermanyUSt-IdNr.DE
GreeceΑΦΜGR
HungaryANUMHU
IcelandVSKIS
IrelandVAT noIE
ItalyP.IVAIT
LatviaPVNLV
LithuaniaPVM kodasLT
LuxembourgNo. TVALU
MaltaVat No.MT
NetherlandsBtw-nr.NL
NorwayOrgnrNO
PolandNIPPL
PortugalNIF / NIPCPT
RomaniaCIFRO
RussiaИННRU
SerbiaPIBRS
SlovakiaIČ DPHSK
SloveniaID za DDVSI
South Africa-ZA
SpainNIF / CIFES
SwedenMomsnr.SE
SwitzerlandMWST / TVA / IVACH
United KingdomVAT Reg NoGB
VenezuelaRIFVE
Using the ES6 module
// You might need to change the importing path
import { vat } from '/vendors/@form-validation/cjs/validator-vat';
const result = vat().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
}
*/
Using the npm package
  • Install the validator package:
$ npm install @form-validation/validator-vat
  • Use the vat validator:
import { vat } from '@form-validation/validator-vat';
const result = vat().validate({
value: ...,
options: {
// Can be a string or a function returns a string
country: ...,
message: ...,
},
});

Basic example

vat validator

NPM package example

The following snippet shows how to use the vat validator with the npm package:
import { vat } from '@form-validation/validator-vat';
const res1 = vat().validate({
value: 'U13585627',
options: {
country: 'AT',
message: 'The value is not a valid VAT number',
},
});
// res1.valid === true
const res2 = vat().validate({
value: '13585627',
options: {
country: 'DK',
message: 'The value is not a valid VAT number',
},
});
// res2.valid === false

See also

Changelog

v2.1.0
  • The validator doesn't work properly if the message property isn't defined
v2.0.0
  • Add the npm package
  • The German VAT numbers don't start with 0
  • The Luxembourgian VAT number validator doesn't work with some numbers
v1.8.0
  • The Bulgarian VAT validator doesn't work for some VAT numbers
  • The French VAT validator doesn't work for some VAT numbers
v1.7.0
  • Support new format of Dutch VAT number
v1.6.0
  • Fixed an issue that the country option isn't passed to the placeholder message
v1.4.0
  • Separate vat validators to vat package to save imports when using with ES6 module
  • Support the Argentinian VAT number
  • Support the Swiss VAT numbers that end with TVA, IVA, TPV