Skip to content

Commit

Permalink
Adjust Swiss uid module to accept numbers without CHE prefix
Browse files Browse the repository at this point in the history
Closes #437
Closes #423
  • Loading branch information
jeffh92 authored and arthurdejong committed Jun 23, 2024
1 parent 91959bd commit 1da003f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion stdnum/ch/uid.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
This module only supports the "new" format that was introduced in 2011 which
completely replaced the "old" 6-digit format in 2014.
Stripped numbers without the CHE prefix are allowed and validated,
but are returned with the prefix prepended.
More information:
Expand All @@ -34,6 +36,8 @@
>>> validate('CHE-100.155.212')
'CHE100155212'
>>> validate('100.155.212')
'CHE100155212'
>>> validate('CHE-100.155.213')
Traceback (most recent call last):
...
Expand All @@ -49,7 +53,10 @@
def compact(number):
"""Convert the number to the minimal representation. This strips
surrounding whitespace and separators."""
return clean(number, ' -.').strip().upper()
number = clean(number, ' -.').strip().upper()
if len(number) == 9 and isdigits(number):
number = 'CHE' + number
return number


def calc_check_digit(number):
Expand Down

0 comments on commit 1da003f

Please sign in to comment.