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

Abandoned → [olssonm/swedish-entity](/?search=olssonm%2Fswedish-entity)ArchivedLibrary[Validation &amp; Sanitization](/categories/validation)

olssonm/identity-number
=======================

Laravel validator for Swedish personal identity numbers / social security numbers (personnummer)

v7.0(5y ago)17168.0k↓64%21MITPHPPHP ^7.2

Since Aug 8Pushed 5y ago1 watchersCompare

[ Source](https://github.com/olssonm/identity-number)[ Packagist](https://packagist.org/packages/olssonm/identity-number)[ Docs](https://github.com/olssonm/identity-number)[ RSS](/packages/olssonm-identity-number/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (2)Versions (22)Used By (1)

Swedish "personnummer" validator for Laravel
============================================

[](#swedish-personnummer-validator-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/893035d75c1cc2dbcf4bb9877f282e577c77592518a83de6aaaba13188b45b49/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6c73736f6e6d2f6964656e746974792d6e756d6265722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/olssonm/identity-number)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/1d0347dea424b1e7174594006b6cbc18d9b2550767eff6f098e6120f463c9a7a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6f6c73736f6e6d2f6964656e746974792d6e756d6265722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/olssonm/identity-number)[![Scrutinizer Score](https://camo.githubusercontent.com/749acb141bc0a81692563caf97d1b10ba6dad665eea5ab4b3d258172cb4bc955/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6f6c73736f6e6d2f6964656e746974792d6e756d6265722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/olssonm/identity-number)

---

⚠️ **Abandoned** This package has been abandoned in favor of [olssonm/swedish-entity](https://github.com/olssonm/swedish-entity).

While the package will be usable for the forseeable future, it will not be updated. Please migrate to `olssonm/swedish-entity` when possible.

---

Validator for Swedish "personnummer" (a.k.a. personal identity number, social security number or simply "PIN").

This validator also handles Swedish organization numbers and the temporary personal identity number known as "Samordningsnummer" (a.k.a. coordination number).

For use either as a standalone package, or with Laravel.

The package does not only apply the Luhn-algorithm for the last four digits, but also checks that the date of birth is a valid date.

Of course you can throw pretty much any format you wish at the validator, ie. 10-digit variant (`7712112775`) or the 12-digit variant (`197712112775`) and with or without a hyphen (`771211-2775`, `19771211-2775`).

Install
-------

[](#install)

Via Composer

```
$ composer require olssonm/identity-number
```

**Within Laravel**

This package uses Package Auto-Discovery for loading the service provider. Once installed you should see the message

```
Discovered Package: olssonm/identity-number

```

Else, per standard Laravel-procedure, just register the package in your providers array:

```
'providers' => [
    Olssonm\IdentityNumber\IdentityNumberServiceProvider::class,
]
```

Usage
-----

[](#usage)

### Standalone

[](#standalone)

The package is usable straight out of the box once installed with composer:

```
use Olssonm\IdentityNumber\Pin;
```

#### Personnummer ("personal identity number")

[](#personnummer-personal-identity-number)

```
Pin::isValid('19771211-2775'); // Defaults to identity number
// true

Pin::isValid('19771211-2775', 'identity'); // Identity validation specified
// true
```

#### Organisationsnummer ("organization number")

[](#organisationsnummer-organization-number)

```
Pin::isValid('556016-0681', 'organization')
// true
```

#### Samordningsnummer ("coordination number")

[](#samordningsnummer-coordination-number)

```
Pin::isValid('19671180-2850', 'coordination');
// true
```

The coordination-number validator handles the same way as the personal identity-validator but does not run a check/validation on the date of birth.

### The IdentityNumberFormatter-class

[](#the-identitynumberformatter-class)

The IdentityNumberFormatter-class allows you to format a PIN/identity for your custom needs. The class is also used internally for validation, but if you want to make sure you save the same value in the database as you pass for validation – you should also apply the formatting before validating.

```
use Olssonm\IdentityNumber\IdentityNumberFormatter;

// Format to a 10-character PIN without a seperator
$formatter = new IdentityNumberFormatter('19860210-7313', 10, false);

// Get the formatted output
$formatter->getFormatted(); // 8602107313

// You can also clean the number from all unwanted characters
(new IdentityNumberFormatter('a19860210 - 7313', 12, true))->clean()->getFormatted(); // 19860210-7313
```

### Laravel validators

[](#laravel-validators)

The package extends the `Illuminate\Validator` via a service provider, so all you have to do is use the `identity_number`-, `coordination_number`- and `organization_number`-rules, just as you would with any other rule.

```
// Personal identity numbers
public function store(Request $request) {
    $this->validate($request, [
        'number' => 'required|identity_number'
    ]);
}

// Coordination numbers
public function store(Request $request) {
    $this->validate($request, [
        'number' => 'required|coordination_number'
    ]);
}

// Organization numbers
public function store(Request $request) {
    $this->validate($request, [
        'number' => 'required|organization_number'
    ]);
}
```

And of course, you can roll your own error messages:

```
$validator = Validator::make($request->all(), [
    'number' => 'required|identity_number'
], [
    'number.identity_number' => "Hey! That's not a personnummer!"
]);

if($validator->fails()) {
    return $this->returnWithErrorAndInput($validator);
}
```

If you're using the validation throughout your application, you also might want to put the error message in your lang-files.

Testing
-------

[](#testing)

```
$ composer test
```

or

```
$ phpunit
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

© 2020 [Marcus Olsson](https://marcusolsson.me).

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community11

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

Recently: every ~162 days

Total

18

Last Release

2033d ago

Major Versions

v2.0 → v3.02016-08-25

v3.0 → v4.0-beta2016-10-13

v4.2 → v5.02017-08-31

v5.3 → v6.02019-03-01

v6.3 → v7.02020-12-09

PHP version history (5 changes)v1.0PHP &gt;=5.3.0

v4.1PHP &gt;=5.6.0

v5.0PHP &gt;=5.6.0|&gt;=7.0

v6.0PHP &gt;=7.0

v6.1PHP ^7.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/907114?v=4)[Marcus Olsson](/maintainers/olssonm)[@olssonm](https://github.com/olssonm)

---

Top Contributors

[![olssonm](https://avatars.githubusercontent.com/u/907114?v=4)](https://github.com/olssonm "olssonm (61 commits)")

---

Tags

laravellaravel-5-packagepersonnummervalidationlaravelpackageolssonmSwedishPersonnummerSocial security numberpersonal identity number

### Embed Badge

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

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

###  Alternatives

[olssonm/swedish-entity

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

15210.2k](/packages/olssonm-swedish-entity)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k16.9M109](/packages/bensampo-laravel-enum)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[sandermuller/laravel-fluent-validation

Fluent validation rule builders for Laravel

20719.0k4](/packages/sandermuller-laravel-fluent-validation)[olssonm/l5-zxcvbn

Implementation of the zxcvbn project by @dropbox for Laravel. Uses zxcvbn-php by @bjeavons.

29333.3k1](/packages/olssonm-l5-zxcvbn)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)

PHPackages © 2026

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