https://github.com/reload/cpr
Danish civil registration numbers (CPR) in PHP
https://github.com/reload/cpr
civil-registration cpr-nummer denmark personal-identification-number php php-library
Last synced: 3 months ago
JSON representation
Danish civil registration numbers (CPR) in PHP
- Host: GitHub
- URL: https://github.com/reload/cpr
- Owner: reload
- License: mit
- Created: 2024-12-03T07:15:32.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-12-12T05:10:18.000Z (11 months ago)
- Last Synced: 2024-12-12T06:18:23.043Z (11 months ago)
- Topics: civil-registration, cpr-nummer, denmark, personal-identification-number, php, php-library
- Language: PHP
- Homepage: https://packagist.org/packages/reload/cpr
- Size: 51.8 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# 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.
```php
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
- [`InvalidCprNumberFormat`](src/Exception/InvalidCprNumberFormat.php)
If the date in the CPR number doesn't
exist.
- [`NonExistingDate`](src/Exception/NonExistingDate.php)
### __toString
Format the CPR number in the traditional format (120345-6789).
```php
public __toString(): string
```
**See Also:**
* \Reload\Cpr\CprNumber::formatPretty()
### formatPretty
Format the CPR number in the traditional format (120345-6789).
```php
public formatPretty(): string
```
### formatNumbersOnly
Format the CPR number using numbers only (1203456789).
```php
public formatNumbersOnly(): string
```
### isFemale
Check if the CPR number represents a female person.
```php
public isFemale(): bool
```
### isMale
Check if the CPR number represents a male person.
```php
public isMale(): bool
```
### getDateTimeImmutable
Get a DateTimeImmutable object from the CPR number.
```php
public getDateTimeImmutable(?\DateTimeZone $timezone = null): ?\DateTimeImmutable
```
**Parameters:**
| Parameter | Type | Description |
|-------------|--------------------|------------------------------------------------------------------------------|
| `$timezone` | **?\DateTimeZone** | A DateTimeZone object for the desired time zone. Defaults: current timezone. |
### validateModulus11
Validate the CPR number using the modulus 11 algorithm.
```php
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.