Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/stdnum/ch/ssn.py
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2016-07-26 18:00:26 +0200
committerArthur de Jong <arthur@arthurdejong.org>2016-07-26 18:03:38 +0200
commit06e41651623798b0bffe37b141374e9ef56c8102 (patch)
tree8335b58c17271e99b4decd6c06ecc58255996768 /stdnum/ch/ssn.py
parent1907c67e756ce5f38422ab75fa1de98fd8368ddc (diff)
Improve validation to Swiss SSN number
The EAN-13 number should start with 756.
Diffstat (limited to 'stdnum/ch/ssn.py')
-rw-r--r--stdnum/ch/ssn.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/stdnum/ch/ssn.py b/stdnum/ch/ssn.py
index 78d72a2..57e88cf 100644
--- a/stdnum/ch/ssn.py
+++ b/stdnum/ch/ssn.py
@@ -1,4 +1,4 @@
-# vat.py - functions for handling Swiss social security numbers
+# ssn.py - functions for handling Swiss social security numbers
#
# Copyright (C) 2014 Denis Krienbuehl
# Copyright (C) 2016 Arthur de Jong
@@ -25,10 +25,11 @@ to identify individuals for taxation and pension purposes.
The number is validated using EAN-13, though dashes are substituted for dots.
->>> compact('756.9217.0769.85')
-'7569217076985'
->>> format('7569217076985')
-'756.9217.0769.85'
+More information:
+
+* https://en.wikipedia.org/wiki/National_identification_number#Switzerland
+* https://de.wikipedia.org/wiki/Sozialversicherungsnummer#Versichertennummer
+
>>> validate('7569217076985')
'7569217076985'
>>> validate('756.9217.0769.85')
@@ -37,6 +38,12 @@ The number is validated using EAN-13, though dashes are substituted for dots.
Traceback (most recent call last):
...
InvalidChecksum: ...
+>>> validate('123.4567.8910.19')
+Traceback (most recent call last):
+ ...
+InvalidComponent: ...
+>>> format('7569217076985')
+'756.9217.0769.85'
"""
from stdnum import ean
@@ -62,6 +69,8 @@ def validate(number):
number = compact(number)
if len(number) != 13:
raise InvalidLength()
+ if not number.startswith('756'):
+ raise InvalidComponent()
return ean.validate(number)