Skip to content

Commit 852515c

Browse files
committed
Fix Czech Rodné číslo check digit validation
It seems that a small minority of numbers assigned with a checksum of 10 are still valid and expected to have a check digit value of 0. According to https://www.domzo13.cz/sw/evok/help/born_numbers.html this practice even happended (but less frequently) after 1985. Closes #468
1 parent fc766bc commit 852515c

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

stdnum/cz/rc.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# rc.py - functions for handling Czech birth numbers
22
# coding: utf-8
33
#
4-
# Copyright (C) 2012-2019 Arthur de Jong
4+
# Copyright (C) 2012-2025 Arthur de Jong
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
@@ -90,14 +90,10 @@ def validate(number):
9090
if len(number) not in (9, 10):
9191
raise InvalidLength()
9292
# check if birth date is valid
93-
birth_date = get_birth_date(number)
94-
# TODO: check that the birth date is not in the future
93+
get_birth_date(number)
9594
# check the check digit (10 digit numbers only)
9695
if len(number) == 10:
97-
check = int(number[:-1]) % 11
98-
# before 1985 the checksum could be 0 or 10
99-
if birth_date < datetime.date(1985, 1, 1):
100-
check = check % 10
96+
check = int(number[:-1]) % 11 % 10
10197
if number[-1] != str(check):
10298
raise InvalidChecksum()
10399
return number

tests/test_cz_rc.doctest

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
test_cz_rc.doctest - more detailed doctests for stdnum.cz.rc
2+
3+
Copyright (C) 2025 Arthur de Jong
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18+
02110-1301 USA
19+
20+
21+
This file contains more detailed doctests for the stdnum.cz.rc
22+
module.
23+
24+
>>> from stdnum.cz import rc
25+
26+
27+
28+
These have been found online and should all be valid numbers.
29+
30+
>>> numbers = '''
31+
...
32+
... 8801251680
33+
...
34+
... '''
35+
>>> [x for x in numbers.splitlines() if x and not rc.is_valid(x)]
36+
[]

0 commit comments

Comments
 (0)