Skip to content

Commit b824cb1

Browse files
committed
Fix VAT numbers validators
1 parent d6b7420 commit b824cb1

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

nip24/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@
4040
from nip24.iban import *
4141
from nip24.nip24client import *
4242

43-
__version__ = '1.3.8'
43+
__version__ = '1.3.9'

nip24/euvat.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,80 +31,78 @@ class EUVAT:
3131
"""
3232

3333
@staticmethod
34-
def normalize(nip):
34+
def normalize(number):
3535
"""
3636
Normalizes form of the VAT number
37-
38-
:param nip: input string
39-
:type nip: str
37+
:param number: input string
38+
:type number: str
4039
:returns: normalized string or False
4140
:rtype: str or False
4241
"""
4342

44-
if not nip:
43+
if not number:
4544
return False
4645

47-
nip = re.sub('[ -]', '', nip).upper()
46+
number = re.sub('[ -]', '', number).upper()
4847

49-
if not re.match('[A-Z]{2}[A-Z0-9]{2,12}', nip):
48+
if not re.match('[A-Z]{2}[A-Z0-9+*]{2,12}', number):
5049
return False
5150

52-
return nip
51+
return number
5352

5453
@staticmethod
55-
def isValid(nip):
54+
def isValid(number):
5655
"""
5756
Checks if specified NIP is valid
58-
59-
:param nip: input string
60-
:type nip: str
57+
:param number: input string
58+
:type number: str
6159
:returns: True if NIP is valid
6260
:rtype: bool
6361
"""
6462

65-
nip = EUVAT.normalize(nip)
63+
number = EUVAT.normalize(number)
6664

67-
if not nip:
65+
if not number:
6866
return False
6967

7068
map = {
7169
'AT': 'ATU\\d{8}',
72-
'BE': 'BE0\\d{9}',
70+
'BE': 'BE[0-1]{1}\\d{9}',
7371
'BG': 'BG\\d{9,10}',
7472
'CY': 'CY\\d{8}[A-Z]{1}',
7573
'CZ': 'CZ\\d{8,10}',
7674
'DE': 'DE\\d{9}',
7775
'DK': 'DK\\d{8}',
7876
'EE': 'EE\\d{9}',
7977
'EL': 'EL\\d{9}',
80-
'ES': 'ES[A-Z0-9]{9}',
78+
'ES': 'ES[A-Z0-9]{1}\\d{7}[A-Z0-9]{1}',
8179
'FI': 'FI\\d{8}',
8280
'FR': 'FR[A-Z0-9]{2}\\d{9}',
83-
'GB': 'GB[A-Z0-9]{5,12}',
8481
'HR': 'HR\\d{11}',
8582
'HU': 'HU\\d{8}',
86-
'IE': 'IE[A-Z0-9]{8,9}',
83+
'IE': 'IE[A-Z0-9+*]{8,9}',
8784
'IT': 'IT\\d{11}',
8885
'LT': 'LT\\d{9,12}',
8986
'LU': 'LU\\d{8}',
9087
'LV': 'LV\\d{11}',
9188
'MT': 'MT\\d{8}',
92-
'NL': 'NL\\d{9}B\\d{2}',
89+
'NL': 'NL[A-Z0-9+*]{12}',
9390
'PL': 'PL\\d{10}',
9491
'PT': 'PT\\d{9}',
9592
'RO': 'RO\\d{2,10}',
9693
'SE': 'SE\\d{12}',
9794
'SI': 'SI\\d{8}',
98-
'SK': 'SK\\d{10}'
95+
'SK': 'SK\\d{10}',
96+
'XI': 'XI[A-Z0-9]{5,12}'
9997
}
10098

101-
cc = nip[0:2].upper()
102-
num = nip[2:].upper()
99+
cc = number[0:2].upper()
100+
num = number[2:].upper()
103101

104102
if cc not in map:
105103
return False
106104

107-
if not re.match(map[cc], nip):
105+
if not re.match(map[cc], number):
108106
return False
109107

110108
if cc == 'PL':

nip24/nip24client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class NIP24Client:
4141
NIP24 service client
4242
"""
4343

44-
VERSION = '1.3.8'
44+
VERSION = '1.3.9'
4545

4646
PRODUCTION_URL = 'https://www.nip24.pl/api'
4747
TEST_URL = 'https://www.nip24.pl/api-test'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from setuptools import setup
2424

2525
setup(name='nip24',
26-
version='1.3.8',
26+
version='1.3.9',
2727
description='NIP24 Service Client',
2828
url='https://www.nip24.pl',
2929
author='nip24.pl',

0 commit comments

Comments
 (0)