Skip to content

Repository files navigation

CprNumber

A class representing Danish civil registration numbers (CPR numbers).

The CPR number is a ten digit number with the format DDMMYY-SSSS, where the first six digits represent the date of birth and the last four digits are a sequence number.

The CPR number is used in Denmark to uniquely identify persons in various systems, and is also used as a personal identification number in many contexts.

The class represents a CPR number as a read-only value object, and provides methods for working with, formatting, and validating CPR numbers.

  • Full name: \Reload\Cpr\CprNumber

Methods

__construct

Construct a CPR number readonly value object from a string.

public__construct(string $cpr)

Parameters:

ParameterTypeDescription
$cprstringA string with the CPR number.

Throws:

If the CPR number does not contain 10 digits

__toString

Format the CPR number in the traditional format (120345-6789).

public__toString(): string

See Also:

  • \Reload\Cpr\CprNumber::formatPretty()

formatPretty

Format the CPR number in the traditional format (120345-6789).

publicformatPretty(): string

formatNumbersOnly

Format the CPR number using numbers only (1203456789).

publicformatNumbersOnly(): string

isFemale

Check if the CPR number represents a female person.

publicisFemale(): bool

isMale

Check if the CPR number represents a male person.

publicisMale(): bool

getDateTimeImmutable

Get a DateTimeImmutable object from the CPR number.

publicgetDateTimeImmutable(?\DateTimeZone $timezone = null): ?\DateTimeImmutable

Parameters:

ParameterTypeDescription
$timezone?\DateTimeZoneA DateTimeZone object for the desired time zone. Defaults: current timezone.

validateModulus11

Validate the CPR number using the modulus 11 algorithm.

publicvalidateModulus11(): bool

NOTICE: CPR numbers are no longer required to fulfill the modulus 11 check. You should NOT use this method to validate or dismiss CPR numbers.

Releases

Used by

Contributors

Languages