python-stdnum
python-stdnum copied to clipboard
Norwegian orgnr validates invalid org numbers.
All norwegian org numbers must be between 800_000_000 and 999_999_999, and your library validates org numbers like "100 000 008". Perhaps a better validation function would be, e.g.
def is_valid(orgnr):
if isinstance(orgnr, str):
orgnr = int(orgnr.replace(" ", "")) # Strip whitespace
elif not isinstance(orgnr, int):
raise TypeError("orgnr must be a str or int.")
if not 800_000_000 <= orgnr < 1_000_000_000:
return False
# Fast way to calculate the checksum
weighted_sum = 0
for weight in [1, 2, 3, 4, 5, 6, 7, 2, 3]:
orgnr, remainder = divmod(orgnr, 10)
weighted_sum += weight * remainder
return not weighted_sum % 11
Hi @LPAiken,
Thanks for reporting this. Do you have a reference somewhere to this extra check? It doesn't seem to be mentioned on https://no.wikipedia.org/wiki/Organisasjonsnummer, https://nn.wikipedia.org/wiki/Organisasjonsnummer or https://www.brreg.no/om-oss/oppgavene-vare/alle-registrene-vare/om-enhetsregisteret/organisasjonsnummeret/.