Validating VAT EEC numbers
Description
tva.py provides a function validating VAT EEC numbers
Source
The source is located in pimentech libcommonPython package: http://www.pimentech.fr/en/technologies/outils , you can also download it here: ftp://ftp.pimentech.net/src/libcommonPython/src/python/libcommon/tva.py
"""
Copyright (C) 2008 PimenTech SARL (http://www.pimentech.fr)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
"""
from string import *
import re
tva_regexps = {
'DE' : r'\d{9}$',
'AT' : r'U\d{8}$',
'BE' : r'0\d{9,10}$',
'BG' : r'\d{9}$',
'CY' : r'\d{8}[A-Za-z]$',
'DK' : r'\d{8}$',
'ES' : r'\w{9}$',
'EE' : r'\d{9}$',
'FI' : r'\d{8}$',
'FR' : r'\d{11}$',
'EL' : r'\d{9}$',
'HU' : r'\d{8}$',
'IE' : r'\w{8}$',
'IT' : r'\d{11}$',
'LV' : r'\d{11}$',
'LT' : r'\d{9}$|\d{12}$',
'LU' : r'\d{8}$',
'MT' : r'\d{8}$',
'NL' : r'\w{12}$',
'PL' : r'\d{10}$',
'PT' : r'\d{9}$',
'SK' : r'\d{10}$',
'CZ' : r'\d{8,10}$',
'RO' : r'\d{2,10}$',
'GB' : r'\w{5}$|\w{9}$|\w{12}$',
'SI' : r'\d{8}$',
'SE' : r'\d{12}$'
}
tva_compiled_regexps = {}
for (country, regexp) in tva_regexps.items():
tva_compiled_regexps[country] = re.compile(regexp)
def is_valid_tva(tva):
try:
country = upper(tva[:2])
return tva_compiled_regexps[country].match(tva[2:])
except:
return False

PDF version