Skip to content
/ bekrafta Public

Bekräfta: Validate Personal Numbers

License

Notifications You must be signed in to change notification settings

Milad/bekrafta

Repository files navigation

Bekräfta Build Status

Bekräfta: A PHP library to perform common operations on Personal Identification Numbers, like: Validation, censoring the individual digits, calculating age and detecting gender.

Supported Countries

  • Denmark (CPR-Nummer)
  • Finland (Henkilötunnus, Personbeteckning)
  • Poland (PESEL)
  • Netherlands (Burgerservicenummer) Validation only
  • Norway (Fødselsnummer)
  • Sweden (Personnummer)

Supported Countries

Supported PHP Versions

  • PHP 7.0
  • PHP 7.1
  • PHP 7.2

Installation

composer require miladk/bekrafta

Usage

This library offers one interface for all supported countries. Developers don't have to use specific countries' classes, instead there is one class that detects and uses the country and serves the appropriate values.

use Bekrafta\PersonalNumber;

$oPN = new PersonalNumber('811228-9874');

// True on successful detection, false otherwise.
// True also means a valid personal number.
$oPN->detect();

// 811228-****
$oPN->getCensored();

// 35
$oPN->getAge();

// m
$oPN->getGender();

// 1981
$oPM->getYear();

// 1981-12-28
$oPM->getBirthday()

Or you can use a specific country if you only need that.

use Bekrafta\Sweden;

$oSweden = new Sweden('811228-9874');

// True on valid personal number, false otherwise.
$oSweden->validate();

// 811228-****
$oSweden->getCensored();

// 35
$oSweden->getAge();

// m
$oSweden->getGender();

// 1981
$oSweden->getYear();

// 1981-12-28
$oSweden->getBirthday();

Sweden Extended

In Sweden, some companies add the century digits as a part of the personal number, or remove the symbol between the date of birth and the four other digits. These changes are not part of the standard of the official standard. So I included to classes for Sweden:

  • Sweden: Supports the official standard format.
  • SwedenExtended: Supports the popular non-standard formats. This has two more functions:
    • removeLeadingCenturies() it removes the leading 19 or 20 from the personal number.
    • removeNonNumbers() Removes non-numeric characters form personal number.

Denmark Strict

However, in 2007 the available sequence numbers under this system for males born on 1 January 1965 ran out, and since October 2007 personal identification numbers do not always validate using the check digit. This had been predicted and announced several years in advance. Thus, most IT systems are presumed updated to accept numbers that fail the check-digit validation. — Wikipedia

Therefore, I see no use for performing a checksum on Danish personal numbers, because we will get false negatives. However, if you want to use the checksum, you can use the class DenmarkStrict which performs the checksum on the personal number, you will get false positives though.

License

MIT