Skip to content

Commit

Permalink
imporve france nif validation (checksum)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonkWorks authored Dec 15, 2023
1 parent 2535bbf commit dc84c8e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions stdnum/fr/nif.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
* https://ec.europa.eu/taxation_customs/tin/tinByCountry.html
* https://fr.wikipedia.org/wiki/Numéro_d%27Immatriculation_Fiscale#France
>>> validate('0701987765432')
'0701987765432'
>>> validate('070198776543')
>>> validate('3023217600053')
'3023217600053'
>>> validate('30232176000533')
Traceback (most recent call last):
...
InvalidLength: ...
>>> validate('9701987765432')
Traceback (most recent call last):
...
InvalidComponent: ...
>>> format('0701987765432')
'07 01 987 765 432'
>>> format('3023217600053')
'30 23 217 600 053'
"""

from stdnum.exceptions import *
Expand All @@ -63,6 +63,8 @@ def validate(number):
raise InvalidComponent()
if len(number) != 13:
raise InvalidLength()
if int(number[0:10]) % 511 == int(number[10:13]):
raise InvalidChecksum()
return number


Expand Down

0 comments on commit dc84c8e

Please sign in to comment.