PHPackages                             komakino/identity - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. komakino/identity

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

komakino/identity
=================

Validation and property parsing of identity numbers

v1.3.0(10y ago)4196.0k↓28.1%2[1 issues](https://github.com/komakino/identity/issues)PHP

Since Jan 14Pushed 10y ago1 watchersCompare

[ Source](https://github.com/komakino/identity)[ Packagist](https://packagist.org/packages/komakino/identity)[ Docs](http://www.github.com/komakino/identity)[ RSS](/packages/komakino-identity/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (6)Used By (0)

Identity
========

[](#identity)

Identity is a composer package to validate, parse, format and extract various information from national identity numbers.

**Current implementations**:

- Swedish personnummer/organisationsnummer
- Danish personnummer/CPR-nummer
- Finnish henkilötunnus/personbeteckning
- Norwegian fødselsnummer

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

[](#installation)

To add this package as a dependency to your project, simply add a dependency on `komakino/identity` to your project's `composer.json` file.

```
    {
        "require": {
            "komakino/identity": "*"
        }
    }
```

Usage
-----

[](#usage)

```
use Komakino\Identity\National\SwedishIdentity;
use Komakino\Identity\National\DanishIdentity;

$swedishIdentity = new SwedishIdentity('011017-2721');
$danishIdentity = new DanishIdentity('170583-7315');
```

### Common methods

[](#common-methods)

Upon construction, the number is parsed and validated.

If number does not comply to the allowed input formats of the implementation, an IdentityInvalidFormatException will be thrown.

#### Public properties

[](#public-properties)

- bool $valid

    - The validity of the identity number
- mixed \*\*getters\*\*

    - All number properties are accessible as properties on the instance

#### Public methods

[](#public-methods)

- array **listProperties**()

    - Returns all number properties
- bool **hasProperty**(string $property)

    - Checks if the identity's implementation has a property
- string **\_\_toString**()

    - Output the formatted identity number

#### Static methods

[](#static-methods)

- static array **parse**(string $number)

    - Creates an instance and returns all number properties
- static bool **validate**(string $number)

    - Creates an instance and returns the validity of the number
- static string **format**(string $number)

    - Output the formatted identity number

### Swedish personnummer/organisationsnummer

[](#swedish-personnummerorganisationsnummer)

#### Allowed input formats

[](#allowed-input-formats)

- `0110172721`
- `011017-2721`
- `011017+2721`
- `200110172721`
- `20011017-2721`
- `20011017+2721`

#### Formatted output

[](#formatted-output)

`011017-2721`

#### Number properties

[](#number-properties)

- **type**
    - *organization* or *person*
- **century**
    - Sources for century:
        - Provided in number as **OO**xxxxxx-xxxx
        - The separator is a *+*, which denotes a person is over 100
        - By logical guessing. Pseudo: `year > current_year ? 19 : 20`
- **year**
    - **OO**xxxx-xxxx
- **month**
    - xx**OO**xx-xxxx
- **day**
    - xxxx**OO**-xxxx
- **centuryHint**
    - xxxxx\*\*-\*\*xxxx
    - Defaults to *-*
- **locality**
    - xxxxxx-**OO**xx
- **county**
    - Only available for people born before 1990
- **number**
    - xxxxxx-xx**O**x
- **gender**
    - *male* or *female*
- **checkdigit**
    - xxxxxx-xxx**O**
- **birthday**
    - A **DateTime** object
- **temporary**
    - If the number is of a temporary nature

### Danish personnummer/CPR-nummer

[](#danish-personnummercpr-nummer)

#### Allowed input formats

[](#allowed-input-formats-1)

- `1705837315`
- `170583-7315`

#### Formatted output

[](#formatted-output-1)

`170583-7315`

#### Number properties

[](#number-properties-1)

- **century**
    - Calculated from *year* and *centuryHint*
- **day**
    - **OO**xxxx-xxxx
- **month**
    - xx**OO**xx-xxxx
- **year**
    - xxxx**OO**-xxxx
- **centuryHint**
    - xxxxxx-**O**xxx
- **sequence**
    - xxxxxx-**OOO0**
- **gender**
    - *male* or *female*
- **birthday**
    - A **DateTime** object

### Finnish personnummer/CPR-nummer

[](#finnish-personnummercpr-nummer)

#### Allowed input formats

[](#allowed-input-formats-2)

- `311280-888Y`

#### Formatted output

[](#formatted-output-2)

`311280-888Y`

#### Number properties

[](#number-properties-2)

- **century**
    - Defined by *centuryHint*
- **day**
    - **OO**xxxx-xxxx
- **month**
    - xx**OO**xx-xxxx
- **year**
    - xxxx**OO**-xxxx
- **centuryHint**
    - xxxxx\*\*-\*\*xxxx
    - *-*/*+*/*A*
- **number**
    - xxxxxx-**OOO**x
- **checkdigit**
    - xxxxxx-xxx**O**
- **gender**
    - *male* or *female*
- **birthday**
    - A **DateTime** object

### Norwegian fødselsnummer

[](#norwegian-fødselsnummer)

#### Allowed input formats

[](#allowed-input-formats-3)

- `17058332143`

#### Formatted output

[](#formatted-output-3)

`17058332143`

#### Number properties

[](#number-properties-3)

- **century**
    - Calculated from *year* and *number*
- **day**
    - **OO**xxxxxxxxx
- **month**
    - xx**OO**xxxxxxx
- **year**
    - xxxx**OO**xxxxx
- **number**
    - xxxxxx**OOO**xx
- **checkdigits**
    - xxxxxxxxx**OO**
- **gender**
    - *male* or *female*
- **birthday**
    - A **DateTime** object
- **D-number**
    - *bool* Whether or not this is a D-number. Temporary number provided to immigrants etc.
- **H-number**
    - *bool* Whether or not this is a H-number. Temporary number used by health care etc.

Changelog
---------

[](#changelog)

### v1.3.0

[](#v130)

- Will now throw an exception if number does'nt comply to the implementations allowed input format.

### v1.2.1

[](#v121)

- Fixed issues with parsing zeros.

### v1.2.0

[](#v120)

- Added implementation for Norwegian fødselsnummer

### v1.1.0

[](#v110)

- Added implementation for Finnish henkilötunnus/personbeteckning

### v1.0.0

[](#v100)

- Initial public release
- Added implementation for Swedish personnummer/organisationsnummer
- Added implementation for Danish personnummer/CPR-nummer

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 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 ~3 days

Total

5

Last Release

3765d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0d2e89d042293e6d2589ecec3813563553b0a6f1ce86a777a421dd759bcb95a1?d=identicon)[komakino](/maintainers/komakino)

---

Top Contributors

[![komakino](https://avatars.githubusercontent.com/u/863727?v=4)](https://github.com/komakino "komakino (10 commits)")

---

Tags

identityvalidatefinnishnumberSsnluhnSwedishPersonnummerSocial security numberOrganisationsnummerpnonorwegiandanishCPR-nummerhenkilötunnuspersonbeteckningfødselsnummer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/komakino-identity/health.svg)

```
[![Health](https://phpackages.com/badges/komakino-identity/health.svg)](https://phpackages.com/packages/komakino-identity)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[olssonm/swedish-entity

Validator and formatter for Swedish personnummer and organisationsnummer. With Laravel validators.

15196.1k](/packages/olssonm-swedish-entity)[intervention/validation

Additional validation rules for the Laravel framework

6826.7M8](/packages/intervention-validation)[ronanguilloux/isocodes

PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Book and Music Industries, Phone numbers &amp; Zipcodes for many countries

8013.3M23](/packages/ronanguilloux-isocodes)[wixel/gump

A fast, extensible &amp; stand-alone PHP input validation class that allows you to validate any data.

1.2k1.3M30](/packages/wixel-gump)[personnummer/personnummer

Validate Swedish social security numbers

34739.3k3](/packages/personnummer-personnummer)

PHPackages © 2026

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