PHPackages                             pinefox/personnummer - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. pinefox/personnummer

ActiveUtility[Utility &amp; Helpers](/categories/utility)

pinefox/personnummer
====================

Validate personal identity numbers

v4.3(8mo ago)14.3kMITPHPPHP &gt;=8.1

Since Dec 13Pushed 8mo agoCompare

[ Source](https://github.com/pinefox/personnummer)[ Packagist](https://packagist.org/packages/pinefox/personnummer)[ RSS](/packages/pinefox-personnummer/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (6)Versions (28)Used By (0)

personnummer
============

[](#personnummer)

- Validate Swedish personnummer (civic numbers), samordningsnummer (coordination numbers), reservnummer (reserve numbers), Danish CPR numbers, and Norwegian birth numbers.
- It is important to note that this library provides only validation.
- Reserve numbers are arbitrarily constructed in different ways, but may look alike. **This means that a given reserve number may also identify as another type of reserve number.**The helper methods for each individual reserve number type will only indicate that the current reserve number has passed validation for that type.

### Different types of reserve numbers

[](#different-types-of-reserve-numbers)

Different reserve number standards are used in specific Swedish regions and may share similarity in their construction.

AbbreviationDescriptionVGRVästra GötalandsregionenSLLRegion Stockholm (former Stockholm läns landsting)RVBRegion VästerbottenInstallation
------------

[](#installation)

```
composer require pinefox/personnummer

```

Methods
-------

[](#methods)

#### Static

[](#static)

MethodArgumentsReturnsparsestring identificationNumber, \[ array options[\*](#options) \]Instancevalidstring identificationNumber, \[ array options[\*](#options) \]bool#### Instance

[](#instance)

MethodArgumentsReturnsformatbool longFormatstringgetAgenoneintisMalenoneboolisFemalenoneboolisPersonalIdentityNumbernoneboolisCoordinationNumbernoneboolisReserveNumbernoneboolisTNumbernoneboolisVgrReserveNumbernoneboolisSllReserveNumbernoneboolisRvbReserveNumbernoneboolisDanishCprNumbernoneboolisNorwegianBirthNumbernoneboolPropertyTypeDescriptioncenturystringCentury, two digitsyearstringYear, two digitsfullYearstringYear, four digitsmonthstringMonth, two digitsdaystringDay, two digitssepstringSeparator (-/+)numstringSuffix number, three digitscheckstringLuhn check digit, one digitErrors
------

[](#errors)

When an identification number is invalid a PersonnummerException is thrown.

Options
-------

[](#options)

OptionTypeDefaultDescriptionallowPersonalIdentityNumberbooltrueAccept Swedish personal identity numbers (YYMMDD-XXXX).allowCoordinationNumberbooltrueAccept coordination numbers.allowTNumberbooltrueAccept reserve numbers with single character in 9th position.allowVgrReserveNumberbooltrueAccept VGR reserve numbers (see specification).allowSllReserveNumberbooltrueAccept SLL reserve numbers (see specification).allowRvbReserveNumberbooltrueAccept RVB reserve numbers (see specification).allowDanishCprNumberbooltrueAccept Danish CPR numbers (DDMMYY-SSSS format).allowNorwegianBirthNumberbooltrueAccept Norwegian birth numbers (11-digit format).Examples
--------

[](#examples)

### Validation

[](#validation)

```
use Personnummer\Personnummer;

Personnummer::valid(1212121212);
//=> true

Personnummer::valid('20121212-1212');
//=> true
```

### Format

[](#format)

```
use Personnummer\Personnummer;

// Short format (YYMMDD-XXXX)
(new Personnummer(1212121212))->format();
//=> 121212-1212

// Short format for 100+ years old
(new Personnummer('191212121212'))->format();
//=> 121212+1212

// Long format (YYYYMMDDXXXX)
(new Personnummer('1212121212'))->format(true);
//=> 201212121212
```

### Get Age

[](#get-age)

```
use Personnummer\Personnummer;

(new Personnummer('1212121212'))->age;
//=> 7
```

### Get Sex

[](#get-sex)

```
use Personnummer\Personnummer;

(new Personnummer('1212121212'))->isMale();
//=> true
(new Personnummer('1212121212'))->isFemale();
//=> false
```

### Danish CPR Numbers

[](#danish-cpr-numbers)

```
use Personnummer\Personnummer;

// Validate Danish CPR
Personnummer::valid('010499-9995', ['allowDanishCprNumber' => true]);
//=> true

// Format Danish CPR
(new Personnummer('0104999995', ['allowDanishCprNumber' => true]))->format();
//=> 010499-9995

// Check if it's Danish CPR
(new Personnummer('010499-9995', ['allowDanishCprNumber' => true]))->isDanishCprNumber();
//=> true

// Century determination based on 7th digit and year
(new Personnummer('010499-9995', ['allowDanishCprNumber' => true]))->fullYear;
//=> 1999 (digit 9, year 99 = 1900s)
```

### Norwegian Birth Numbers

[](#norwegian-birth-numbers)

```
use Personnummer\Personnummer;

// Validate Norwegian birth number
Personnummer::valid('03016213704');
//=> true

// Check if it's Norwegian birth number
(new Personnummer('03016213704'))->isNorwegianBirthNumber();
//=> true

// Format Norwegian birth number (no separator)
(new Personnummer('03016213704'))->format();
//=> 03016213704

// Gender determination
(new Personnummer('03016213704'))->isMale(); // Check digit 4 is even = male
//=> true
```

See [PersonnummerTest.php](tests/PersonnummerTest.php) for more examples.

License
-------

[](#license)

MIT

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance59

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 52.3% 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 ~177 days

Recently: every ~397 days

Total

23

Last Release

262d ago

Major Versions

v1.2.1 → v2.0.02019-09-06

v2.1.0 → v3.0.02020-02-18

v3.4.3 → v4.02021-05-25

PHP version history (4 changes)v1.0.0PHP &gt;=5.3.0

v2.1.0PHP &gt;=5.6

v3.0.0PHP &gt;=7.2

v4.2PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1293058?v=4)[Johan Frank](/maintainers/johanfrank)[@johanfrank](https://github.com/johanfrank)

---

Top Contributors

[![frozzare](https://avatars.githubusercontent.com/u/14610?v=4)](https://github.com/frozzare "frozzare (56 commits)")[![rasmusbe](https://avatars.githubusercontent.com/u/2124386?v=4)](https://github.com/rasmusbe "rasmusbe (27 commits)")[![jnrflsh](https://avatars.githubusercontent.com/u/25635481?v=4)](https://github.com/jnrflsh "jnrflsh (7 commits)")[![johanfrank](https://avatars.githubusercontent.com/u/1293058?v=4)](https://github.com/johanfrank "johanfrank (7 commits)")[![uxade](https://avatars.githubusercontent.com/u/15247426?v=4)](https://github.com/uxade "uxade (5 commits)")[![Johannestegner](https://avatars.githubusercontent.com/u/2530181?v=4)](https://github.com/Johannestegner "Johannestegner (2 commits)")[![adhj-dw](https://avatars.githubusercontent.com/u/47565903?v=4)](https://github.com/adhj-dw "adhj-dw (2 commits)")[![lantto](https://avatars.githubusercontent.com/u/2482002?v=4)](https://github.com/lantto "lantto (1 commits)")

---

Tags

utilitysecuritySwedishPersonnummerPersonal idSocial security numberidentifypersonal identity numbersamordningsnummerco-ordinationcoordination

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/pinefox-personnummer/health.svg)

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

###  Alternatives

[personnummer/personnummer

Validate Swedish social security numbers

34739.3k3](/packages/personnummer-personnummer)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.0M191](/packages/danielstjules-stringy)[voku/arrayy

Array manipulation library for PHP, called Arrayy!

4875.5M16](/packages/voku-arrayy)[vaimo/composer-patches

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and patch command for testing/troubleshooting added patches.

2994.3M16](/packages/vaimo-composer-patches)[phpcsstandards/phpcsutils

A suite of utility functions for use with PHP\_CodeSniffer

6233.4M58](/packages/phpcsstandards-phpcsutils)

PHPackages © 2026

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