From 06e41651623798b0bffe37b141374e9ef56c8102 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Tue, 26 Jul 2016 18:00:26 +0200 Subject: Improve validation to Swiss SSN number The EAN-13 number should start with 756. --- stdnum/ch/ssn.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'stdnum/ch/ssn.py') 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) -- cgit v1.2.3