JavaScript EU VAT Number Validation

This function check the validity of the format of an EU VAT number specified by the supplied parameter. Note that it does not check whether the code is currently allocated - this may done by interrogating the EU database.

The specifications of valid VAT numbers were originally gleaned from a variety of sources found on the web, but have since been confirmed using a VIES document. All necessary check digit validation is performed except for the new style French TVA numbers, which are not thought to be yet in use.

Non-EU Norwegian, Serbian, Swiss and Russian VAT formats are also supported.

In this JavaScript function, the country code is mandatory apart from those belonging to the UK, in which case it is optional. A description of how to make a different country's code the default is described in the embedded comments within the downloadable JavaScript code.

Embedded spaces, commas, points, and dashes are accepted, and capitalisation is ignored. If the parameter is a valid VAT number, the function returns the number with any extra characters removed and lower case alphabetic characters converted to uppercase. Otherwise it returns a value of false.

Try the JavaScript routine: Enter VAT Number:

In the following example, the input field has an id of vatnumber, and the button has an onclick="testVATNumber();" associated with it. This latter function calls the main checkVATNumber function as follows:

function testVATNumber () {
  var newVATNumber = checkVATNumber (document.getElementById('vatnumber').value);
  if (newVATNumber) {
    document.getElementById('vatnumber').value = newVATNumber;
    alert ("VAT number has a valid format"); 
  else alert ("VAT number has an invalid format");

See here for the routine's change log and acknowledgements. A test transaction is available here.

Download compressed JavaScript file (8,871 bytes)

Note: This routine was last updated on 29 June 2017 to correct the handling of Czech Republic Type 2 individual formats. Thanks to Andreas Wuermser of Auer Packaging UK.