Skip to content

Norwegian orgnr validates invalid org numbers. #275

Open

Description

@LPAiken

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

Activity

  1. arthurdejong commented on Sep 26, 2021

    @arthurdejong
    Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions