Skip to content

Commit 7ca9b6c

Browse files
committed
Validate first digit of Belgian VAT number
Thanks to antonio-ginestar find pointing this out. Closes #488
1 parent a1fdd5d commit 7ca9b6c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

stdnum/be/vat.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# vat.py - functions for handling Belgian VAT numbers
22
#
3-
# Copyright (C) 2012-2016 Arthur de Jong
3+
# Copyright (C) 2012-2025 Arthur de Jong
44
#
55
# This library is free software; you can redistribute it and/or
66
# modify it under the terms of the GNU Lesser General Public
@@ -67,6 +67,8 @@ def validate(number: str) -> str:
6767
raise InvalidFormat()
6868
if len(number) != 10:
6969
raise InvalidLength()
70+
if not number[0] in '01':
71+
raise InvalidComponent()
7072
if checksum(number) != 0:
7173
raise InvalidChecksum()
7274
return number

tests/test_be_vat.doctest

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
test_be_vat.doctest - more detailed doctests for stdnum.be.vat module
22

3-
Copyright (C) 2020 Arthur de Jong
3+
Copyright (C) 2020-2025 Arthur de Jong
44

55
This library is free software; you can redistribute it and/or
66
modify it under the terms of the GNU Lesser General Public
@@ -31,7 +31,15 @@ Tests for corner cases.
3131
Traceback (most recent call last):
3232
...
3333
InvalidFormat: ...
34+
>>> vat.validate('BE000000000')
35+
Traceback (most recent call last):
36+
...
37+
InvalidFormat: ...
3438
>>> vat.validate('000000')
3539
Traceback (most recent call last):
3640
...
3741
InvalidFormat: ...
42+
>>> vat.validate('BE2000021323')
43+
Traceback (most recent call last):
44+
...
45+
InvalidComponent: ...

0 commit comments

Comments
 (0)