Loading...

How to check for a valid VAT Identification Number

Emilian F. Published on 06 January, 2014

If you sell in the European Union and are registered for VAT then you have to ask your clients for the VAT identification number (VATIN) before issuing an invoice. It is a good idea to make sure the VATIN is valid when generating the invoice otherwise you will have issues with your local tax authority.

Validation can be done manually by using the VAT Information Exchange System (VIES) website or by using a script to do it automatically by accessing the VIES web service via SOAP. The SOAP web service option is faster and less error prone so we came up with a simple script to check if a VAT identification number is valid. Unfortunately there is no RESTful API for the VIES service, so we have to install a library to generate the SOAP requests. Here's what you need to do in order to check VAT identification numbers:

The requirements:

  • Python 2.5 or greater - most web servers have it installed by default
  • the SUDS Python library
  • You can install the SUDS library using pip (a Python package manager). Just run the following command in your command line:

    pip install suds

Once you have SUDS installed create a new Python file with the following code:

from suds.client import Client
from urllib import getproxies

VIES_URL = "http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl"

client = Client(VIES_URL, proxy=getproxies())

response = client.service.checkVat(countryCode='RO', vatNumber='28653549')

print response

The above code will check the VIES database for a company with the RO28653549 identification number which by chance happens to be our VAT number. You will have to replace the countryCode and vatNumber parameter values with your own values in order to validate other VAT identification numbers.

To make the script more useful you can create a function to check the formatting of the identification number based on the country code. Here are the formats for each individual country to help you get started:

Member State Structure Format*
AT-Austria ATU99999999 1 block of 9 characters
BE-Belgium BE0999999999 1 block of 10 digits
BG-Bulgaria BG999999999 or
BG9999999999
1 block of 9 digits or1 block of 10 digits
CY-Cyprus CY99999999L 1 block of 9 characters
CZ-Czech Republic CZ99999999 or
CZ999999999 or
CZ9999999999
1 block of either 8, 9 or 10 digits
DE-Germany DE999999999 1 block of 9 digits
DK-Denmark DK99 99 99 99 4 blocks of 2 digits
EE-Estonia EE999999999 1 block of 9 digits
EL-Greece EL999999999 1 block of 9 digits
ES-Spain ESX9999999X4 1 block of 9 characters
FI-Finland FI99999999 1 block of 8 digits
FR-France FRXX 999999999 1 block of 2 characters, 1 block of 9 digits
GB-United Kingdom GB999 9999 99 or
GB999 9999 99 9995 or
GBGD9996 or
GBHA9997
1 block of 3 digits, 1 block of 4 digits and 1 block of 2 digits; or the above followed by a block of 3 digits; or 1 block of 5 characters
HR-Croatia HR99999999999 1 block of 11 digits
HU-Hungary HU99999999 1 block of 8 digits
IE-Ireland IE9S99999L
IE9999999WI
1 block of 8 characters or 1 block of 9 characters
IT-Italy IT99999999999 1 block of 11 digits
LT-Lithuania LT999999999 or
LT999999999999
1 block of 9 digits, or 1 block of 12 digits
LU-Luxembourg LU99999999 1 block of 8 digits
LV-Latvia LV99999999999 1 block of 11 digits
MT-Malta MT99999999 1 block of 8 digits
NL-The Netherlands NL999999999B998 1 block of 12 characters
PL-Poland PL9999999999 1 block of 10 digits
PT-Portugal PT999999999 1 block of 9 digits
RO-Romania RO999999999 1 block of minimum 2 digits and maximum 10 digits
SE-Sweden SE999999999999 1 block of 12 digits
SI-Slovenia SI99999999 1 block of 8 digits
SK-Slovakia SK9999999999 1 block of 10 digits

The VAT Information Exchange System website has more information on how the data is gathered, and what to do in case the your VAT identification number is invalid.

Emilian F. Published on 06 January, 2014