# stdnum.ro.cnp

CNP (Cod Numeric Personal, Romanian Numerical Personal Code).

The CNP is a 13 digit number that includes information on the person’s gender, birth date and country zone.

More information:

- https://ro.wikipedia.org/wiki/Cod_numeric_personal

- https://github.com/vimishor/cnp-spec/blob/master/spec.md

    >>> validate('1630615123457')
    '1630615123457'
    >>> get_county('1630615123457')
    'Cluj'
    >>> validate('0800101221142')  # invalid first digit
    Traceback (most recent call last):
        ...
    InvalidComponent: ...
    >>> validate('1632215123457')  # invalid date
    Traceback (most recent call last):
        ...
    InvalidComponent: ...
    >>> validate('1630615993454')  # invalid county
    Traceback (most recent call last):
        ...
    InvalidComponent: ...
    >>> validate('1630615123458')  # invalid check digit
    Traceback (most recent call last):
        ...
    InvalidChecksum: ...

stdnum.ro.cnp.calc_check_digit(number: str) → str

  Calculate the check digit for personal codes.

stdnum.ro.cnp.compact(number: str) → str

  Convert the number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.

stdnum.ro.cnp.get_birth_date(number: str) → date

  Split the date parts from the number and return the birth date.

stdnum.ro.cnp.get_county(number: str) → str

  Get the county name from the number

stdnum.ro.cnp.is_valid(number: str) → bool

  Check if the number is a valid VAT number.

stdnum.ro.cnp.validate(number: str) → str

  Check if the number is a valid VAT number. This checks the length, formatting and check digit.