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
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": "*"
}
}
use Komakino\Identity\National\SwedishIdentity;
use Komakino\Identity\National\DanishIdentity;
$swedishIdentity = new SwedishIdentity('011017-2721');
$danishIdentity = new DanishIdentity('170583-7315');
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.
-
bool $valid
- The validity of the identity number
-
mixed **getters**
- All number properties are accessible as properties on the instance
-
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 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
0110172721
011017-2721
011017+2721
200110172721
20011017-2721
20011017+2721
011017-2721
- 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
- Sources for century:
- 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
1705837315
170583-7315
170583-7315
- 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
311280-888Y
311280-888Y
- 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
17058332143
17058332143
- 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.
- Will now throw an exception if number does'nt comply to the implementations allowed input format.
- Fixed issues with parsing zeros.
- Added implementation for Norwegian fødselsnummer
- Added implementation for Finnish henkilötunnus/personbeteckning
- Initial public release
- Added implementation for Swedish personnummer/organisationsnummer
- Added implementation for Danish personnummer/CPR-nummer