2017 © Pedro Peláez
 

library identity-number

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

image

olssonm/identity-number

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

  • Friday, January 19, 2018
  • by olssonm
  • Repository
  • 1 Watchers
  • 14 Stars
  • 1,221 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 13 Versions
  • 10 % Grown

The README.md

Swedish "personnummer" validator for Laravel

Latest Version on Packagist ![Software License][ico-license] Build Status ![Scrutinizer Score][ico-scrutinizer], (*1)


⚠️ Abandoned This package has been abandoned in favor of olssonm/swedish-entity., (*2)

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


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

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

For use either as a standalone package, or with Laravel., (*6)

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., (*7)

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)., (*8)

Install

Via Composer, (*9)

``` bash $ composer require olssonm/identity-number, (*10)


**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, (*11)


Else, per standard Laravel-procedure, just register the package in your providers array: ``` php 'providers' => [ Olssonm\IdentityNumber\IdentityNumberServiceProvider::class, ]

Usage

Standalone

The package is usable straight out of the box once installed with composer:, (*12)

``` php use Olssonm\IdentityNumber\Pin;, (*13)


#### Personnummer ("personal identity number") ``` php Pin::isValid('19771211-2775'); // Defaults to identity number // true Pin::isValid('19771211-2775', 'identity'); // Identity validation specified // true

Organisationsnummer ("organization number")

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


#### Samordningsnummer ("coordination number") ``` php 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., (*15)

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., (*16)


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

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., (*17)

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

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

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


And of course, you can roll your own error messages: ``` php $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., (*21)

Testing

``` bash $ composer test, (*22)


or ``` bash $ phpunit

License

The MIT License (MIT). Please see License File for more information., (*23)

© 2020 Marcus Olsson., (*24)

The Versions

19/01 2018

dev-master

9999999-dev https://github.com/olssonm/identity-number

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

  Sources   Download

MIT

The Requires

 

The Development Requires

swedish personnummer social security number personal identity number olssonm

19/01 2018

v5.1

5.1.0.0 https://github.com/olssonm/identity-number

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

  Sources   Download

MIT

The Requires

 

The Development Requires

swedish personnummer social security number personal identity number olssonm

19/01 2018

dev-dev

dev-dev https://github.com/olssonm/identity-number

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

  Sources   Download

MIT

The Requires

 

The Development Requires

swedish personnummer social security number personal identity number olssonm

31/08 2017

v5.0

5.0.0.0 https://github.com/olssonm/identity-number

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

  Sources   Download

MIT

The Requires

 

The Development Requires

swedish personnummer social security number personal identity number olssonm

28/03 2017

v4.2

4.2.0.0 https://github.com/olssonm/identity-number

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

  Sources   Download

MIT

The Requires

 

The Development Requires

swedish personnummer social security number personal identity number olssonm

29/01 2017

v4.1

4.1.0.0 https://github.com/olssonm/identity-number

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

  Sources   Download

MIT

The Requires

 

The Development Requires

swedish personnummer social security number personal identity number olssonm

03/11 2016

v4.0

4.0.0.0 https://github.com/olssonm/identity-number

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

  Sources   Download

MIT

The Requires

 

The Development Requires

swedish personnummer social security number personal identity number olssonm

13/10 2016

v4.0-beta

4.0.0.0-beta https://github.com/olssonm/identity-number

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

  Sources   Download

MIT

The Requires

 

The Development Requires

swedish personnummer social security number personal identity number olssonm

25/08 2016

v3.0

3.0.0.0 https://github.com/olssonm/identity-number

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

  Sources   Download

MIT

The Requires

 

The Development Requires

swedish personnummer social security number personal identity number olssonm

15/06 2016

v2.0

2.0.0.0 https://github.com/olssonm/identity-number

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

  Sources   Download

MIT

The Requires

 

The Development Requires

swedish personnummer social security number personal identity number olssonm

19/11 2015

v1.2

1.2.0.0 https://github.com/olssonm/identity-number

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

  Sources   Download

MIT

The Requires

 

The Development Requires

swedish personnummer social security number personal identity number olssonm

10/08 2015

v1.1

1.1.0.0 https://github.com/olssonm/identity-number

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

  Sources   Download

MIT

The Requires

 

The Development Requires

swedish personnummer social security number personal identity number olssonm

08/08 2015

v1.0

1.0.0.0 https://github.com/olssonm/identity-number

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

  Sources   Download

MIT

The Requires

 

The Development Requires

swedish personnummer social security number personal identity number olssonm