PHPackages                             jontsa/national-identification-number - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. jontsa/national-identification-number

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

jontsa/national-identification-number
=====================================

Parse national identification numbers.

1.0.1(4y ago)01.6kMITPHPPHP ^7.4.0|^8.0

Since Mar 2Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Jontsa/national-identification-number)[ Packagist](https://packagist.org/packages/jontsa/national-identification-number)[ Docs](https://github.com/Jontsa/national-identification-number)[ RSS](/packages/jontsa-national-identification-number/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

PHP classes to parse, validate and format personal identification numbers
=========================================================================

[](#php-classes-to-parse-validate-and-format-personal-identification-numbers)

[![Tests](https://github.com/Jontsa/national-identification-number/workflows/Tests/badge.svg)](https://github.com/Jontsa/national-identification-number/workflows/Tests/badge.svg)

This package can be used to parse, validate and format national personal identification numbers. In some countries these might be called social security numbers, national insurance numbers etc.

There are other similar packages available but some are not updated anymore, some do not work with newer PHP versions, some only support one country etc. This package was created to better suit our needs. It only supports limited set of countries but adding new countries should be easy if syntax is described somewhere.

Features
--------

[](#features)

- Parse and validate national identifier string
- Returns object with known properties extracted from the identifier
- Supported countries
    - Austria
    - Estonia
    - Finland
    - Sweden both personal- and organization numbers
    - United Kingdom NI Number

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- composer

Installation
------------

[](#installation)

Make sure Composer is installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md)of the Composer documentation.

Open a command console, enter your project directory and execute:

```
$ composer require jontsa/national-identification-number
```

Usage
-----

[](#usage)

Parse and validate identity number:

```
use Jontsa\NationalIdentificationNumber\Exception\InvalidIdentifierExceptionInterface;
use Jontsa\NationalIdentificationNumber\Exception\InvalidSyntaxExceptionInterface;
use Jontsa\NationalIdentificationNumber\Exception\UnsupportedCountryException;
use Jontsa\NationalIdentificationNumber\Factory;
use Jontsa\NationalIdentificationNumber\IdentificationNumber\BirthDateAwareInterface;
use Jontsa\NationalIdentificationNumber\IdentificationNumber\GenderAwareInterface;

$country = 'FI';
$string = '150921A123A';
try {
    $identificationNumber = Factory::create($country, $string);
    echo "Yay, this is a valid personal identification number.\n";
    if ($identificationNumber instanceof BirthDateAwareInterface) {
        if ($identificationNumber instanceof GenderAwareInterface) {
            $pronoun = $identificationNumber->getGender() === GenderAwareInterface::GENDER_MALE ? 'He' : 'She';
        } else {
            $pronoun = 'Person'
        }
        echo $pronoun . " was born on " . $identificationNumber->getBirthDate()->format('Y-m-d') . "\n";
    }
} catch (UnsupportedCountryException $e) {
    echo 'Sorry but ' . $country . ' is not supported. Maybe you can create a ticket or PR in Github?';
} catch (InvalidSyntaxExceptionInterface|InvalidIdentifierExceptionInterface $e) {
    echo 'The supplied string was not a valid personal identification number';
}
```

Alternative method for parsing identity number for specific country:

```
use Jontsa\NationalIdentificationNumber\Exception\InvalidIdentifierExceptionInterface;
use Jontsa\NationalIdentificationNumber\Exception\InvalidSyntaxExceptionInterface;
use Jontsa\NationalIdentificationNumber\Factory;

try {
    $identificationNumber = Factory::FI('150921A123A');
    echo "Yay, this is a valid personal identification number.\n";
    echo 'Gender: ' . $identificationNumber->getGender() . "\n";
    echo 'Born: ' . $identificationNumber->getBirthDate() . "\n";
} catch (InvalidSyntaxExceptionInterface|InvalidIdentifierExceptionInterface $e) {
    echo 'The supplied string was not valid Finnish personal identification number';
}
```

Calculate checksum and format Finnish personal identity number:

```
use Jontsa\NationalIdentificationNumber\IdentificationNumber\FinnishIdentificationNumber;

$identificationNumber = new FinnishIdentificationNumber('19', '-', '79', '01', '31', '082');
echo 'Correct checksum: ' . $identificationNumber->getCheckSum() . "\n";
echo 'Formatted: ' . $identificationNumber->format() . "\n";

// output
// Correct checksum: U
// Formatted: 310179-082U
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

2

Last Release

1580d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17642317?v=4)[Joni Halme](/maintainers/jontsa)[@Jontsa](https://github.com/Jontsa)

---

Top Contributors

[![Jontsa](https://avatars.githubusercontent.com/u/17642317?v=4)](https://github.com/Jontsa "Jontsa (5 commits)")

---

Tags

Personal idSocial security numbernational identification number

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jontsa-national-identification-number/health.svg)

```
[![Health](https://phpackages.com/badges/jontsa-national-identification-number/health.svg)](https://phpackages.com/packages/jontsa-national-identification-number)
```

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19139.2M45](/packages/mck89-peast)[personnummer/personnummer

Validate Swedish social security numbers

36809.1k4](/packages/personnummer-personnummer)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9843.5k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

45153.1k6](/packages/jstewmc-rtf)[tcds-io/php-jackson

A lightweight, flexible object serializer for PHP, inspired by FasterXML/jackson

113.2k10](/packages/tcds-io-php-jackson)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
