blob: 712b511eb33715a41feac2011b7bded7cc73488e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# onderwijsnummer.py - functions for handling onderwijsnummers
#
# Copyright (C) 2012 Arthur de Jong
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
"""Module for handling onderwijsnummers (school number), very similar to
the BSN (Dutch national identification number) but for students without a
BSN.
>>> is_valid('101222331')
True
>>> is_valid('100252333')
False
>>> compact('1234.56.782')
'123456782'
"""
from stdnum.nl.bsn import compact, checksum
def is_valid(number):
"""Checks to see if the number provided is a valid onderwijsnummer.
This checks the length and whether the check digit is correct and
whether it starts with the right sequence."""
try:
number = compact(number)
except:
return False
return len(number) == 9 and \
number.isdigit() and \
int(number) > 0 and \
checksum(number) == 5 and \
number.startswith('10')
|