stdnum.dk.cpr

CPR (personnummer, the Danish citizen number).

The CPR is the national number to identify Danish citizens. The number consists of 10 digits in the format DDMMYY-SSSS where the first part represents the birth date and the second a sequence number. The first digit of the sequence number indicates the century.

The numbers used to validate using a checksum but since the sequence numbers ran out this was abandoned in 2007.

>>> validate('211062-5629')
'2110625629'
>>> checksum('2110625629')
0
>>> validate('511062-5629')  # invalid date
Traceback (most recent call last):
    ...
InvalidComponent: ...
>>> get_birth_date('2110620629')
datetime.date(1962, 10, 21)
>>> get_birth_date('2110525629')
datetime.date(2052, 10, 21)
>>> format('2110625629')
'211062-5629'
stdnum.dk.cpr.checksum(number)

Calculate the checksum. Note that the checksum isn’t actually used any more. Valid numbers used to have a checksum of 0.

stdnum.dk.cpr.compact(number)

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

stdnum.dk.cpr.format(number)

Reformat the passed number to the standard format.

stdnum.dk.cpr.get_birth_date(number)

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

stdnum.dk.cpr.is_valid(number)

Checks to see if the number provided is a valid CPR number. This checks the length, formatting, embedded date and check digit.

stdnum.dk.cpr.validate(number)

Checks to see if the number provided is a valid CPR number. This checks the length, formatting, embedded date and check digit.

Previous topic

stdnum.de.vat

Next topic

stdnum.dk.cvr