8000 Improve French NIF validation · cedk/python-stdnum@eeaf665 · GitHub
[go: up one dir, main page]

Skip to content

Commit eeaf665

Browse files
DimitriPapadopoulosarthurdejong
authored andcommitted
Improve French NIF validation
Closes arthurdejong#266
1 parent e2a95fc commit eeaf665

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

stdnum/fr/nif.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# nif.py - functions for handling French tax identification numbers
22
# coding: utf-8
33
#
4-
# Copyright (C) 2016 Dimitri Papadopoulos
4+
# Copyright (C) 2016-2021 Dimitri Papadopoulos
55
#
66
# This library is free software; you can redistribute it and/or
77
# modify it under the terms of the GNU Lesser General Public
@@ -20,10 +20,10 @@
2020

2121
"""NIF (Numéro d'Immatriculation Fiscale, French tax identification number).
2222
23-
The NIF (Numéro d'Immatriculation Fiscale, Numéro d'Identité Fiscale or
24-
Numéro d'Identification Fiscale) also known as numéro fiscal de référence or
25-
SPI (Simplification des Procédures d'Identification) is a 13-digit number
26-
issued by the French tax authorities to people for tax reporting purposes.
23+
The NIF (Numéro d'Immatriculation Fiscale or Numéro d'Identification Fiscale)
24+
also known as numéro fiscal de référence or SPI (Simplification des
25+
Procédures d'Identification) is a 13-digit number issued by the French tax
26+
authorities to people for tax reporting purposes.
2727
2828
More information:
2929
@@ -36,6 +36,10 @@
3636
Traceback (most recent call last):
3737
...
3838
InvalidLength: ...
39+
>>> validate('9701987765432')
40+
Traceback (most recent call last):
41+
...
42+
InvalidComponent: ...
3943
>>> format('0701987765432')
4044
'07 01 987 765 432'
4145
"""
@@ -55,6 +59,8 @@ def validate(number):
5559
number = compact(number)
5660
if not isdigits(number):
5761
raise InvalidFormat()
62+
if number[0] not in ('0', '1', '2', '3'):
63+
raise InvalidComponent()
5864
if len(number) != 13:
5965
raise InvalidLength()
6066
return number

0 commit comments

Comments
 (0)
0