Giter Club home page Giter Club logo

identity's Introduction

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

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

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

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

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

  • bool $valid

    • The validity of the identity number
  • mixed **getters**

    • All number properties are accessible as properties on the instance

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 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

Allowed input formats

  • 0110172721
  • 011017-2721
  • 011017+2721
  • 200110172721
  • 20011017-2721
  • 20011017+2721

Formatted output

011017-2721

Number properties

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

Danish personnummer/CPR-nummer

Allowed input formats

  • 1705837315
  • 170583-7315

Formatted output

170583-7315

Number properties

  • century
    • Calculated from year and centuryHint
  • day
    • OOxxxx-xxxx
  • month
    • xxOOxx-xxxx
  • year
    • xxxxOO-xxxx
  • centuryHint
    • xxxxxx-Oxxx
  • sequence
    • xxxxxx-OOO0
  • gender
    • male or female
  • birthday
    • A DateTime object

Finnish personnummer/CPR-nummer

Allowed input formats

  • 311280-888Y

Formatted output

311280-888Y

Number properties

  • century
    • Defined by centuryHint
  • day
    • OOxxxx-xxxx
  • month
    • xxOOxx-xxxx
  • year
    • xxxxOO-xxxx
  • centuryHint
    • xxxxx**-**xxxx
    • -/+/A
  • number
    • xxxxxx-OOOx
  • checkdigit
    • xxxxxx-xxxO
  • gender
    • male or female
  • birthday
    • A DateTime object

Norwegian fødselsnummer

Allowed input formats

  • 17058332143

Formatted output

17058332143

Number properties

  • century
    • Calculated from year and number
  • day
    • OOxxxxxxxxx
  • month
    • xxOOxxxxxxx
  • year
    • xxxxOOxxxxx
  • number
    • xxxxxxOOOxx
  • checkdigits
    • xxxxxxxxxOO
  • 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

v1.3.0

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

v1.2.1

  • Fixed issues with parsing zeros.

v1.2.0

  • Added implementation for Norwegian fødselsnummer

v1.1.0

  • Added implementation for Finnish henkilötunnus/personbeteckning

v1.0.0

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

identity's People

Contributors

komakino avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.