reload / cpr
CPR: Danish personal identification numbers
Requires
- php: ^8.3
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- phpcompatibility/php-compatibility: ^9.3
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- phpstan/phpstan-deprecation-rules: ^2.0
- phpunit/phpunit: ^12.0
- saggre/phpdocumentor-markdown: ^0.1.4
- sempro/phpunit-pretty-print: ^1.2
- squizlabs/php_codesniffer: ^3.11
- dev-main
- v0.0.33
- v0.0.32
- v0.0.31
- v0.0.30
- v0.0.29
- v0.0.28
- v0.0.27
- v0.0.26
- v0.0.25
- v0.0.24
- v0.0.23
- v0.0.22
- v0.0.21
- v0.0.20
- v0.0.19
- v0.0.18
- v0.0.17
- v0.0.16
- v0.0.15
- v0.0.14
- v0.0.13
- v0.0.12
- v0.0.11
- v0.0.10
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.3
- v0.0.2
- v0.0.1
- dev-dependabot/composer/phpunit/phpunit-12.0.4
This package is auto-updated.
Last update: 2025-02-21 23:07:03 UTC
README
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:
Parameter | Type | Description |
---|---|---|
$cpr |
string | A string with the CPR number. |
Throws:
If the CPR number does not contain 10 digits
If the date in the CPR number doesn't exist.
__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).
public formatPretty(): string
formatNumbersOnly
Format the CPR number using numbers only (1203456789).
public formatNumbersOnly(): string
isFemale
Check if the CPR number represents a female person.
public isFemale(): bool
isMale
Check if the CPR number represents a male person.
public isMale(): bool
getDateTimeImmutable
Get a DateTimeImmutable object from the CPR number.
public getDateTimeImmutable(?\DateTimeZone $timezone = null): ?\DateTimeImmutable
Parameters:
Parameter | Type | Description |
---|---|---|
$timezone |
?\DateTimeZone | A DateTimeZone object representing the desired time zone. If timezone is omitted or null the current timezone will be used. |
validateModulus11
Validate the CPR number using the modulus 11 algorithm.
public validateModulus11(): 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.