Download the PHP package olssonm/swedish-entity without Composer
On this page you can find all versions of the php package olssonm/swedish-entity. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download olssonm/swedish-entity
More information about olssonm/swedish-entity
Files in olssonm/swedish-entity
Package swedish-entity
Short Description Validator and formatter for Swedish personnummer and organisationsnummer. With Laravel validators.
License MIT
Homepage https://github.com/olssonm/swedish-entity
Informations about the package swedish-entity
Swedish Entity
Validate, format and extract data for Swedish personnummer (social security numbers) and organisationsnummer (organizational numbers).
This package also handles the temporary personal identity number known as "Samordningsnummer" (a.k.a. coordination number).
Also includes validators for Laravel.
–
The benefits of this package – while not always strictly according to the standard – is the ability to format using both short/long (10 or 12 characters) without or with a separator (i.e. 11/13 characters).
Note that companies always consists of 10/11 characters (with or without an optional separator).
This package use the excellent personnummer/php-package as it's basis for the social security-handling, but with some additional attributes and methods.
Installation
Usage
Validation
Automatically detect the entity type:
⚠️ If the
detect
-method fails, anOlssonm\SwedishEntity\Exceptions\DetectException
will be thrown.
Formatting
⚠️ Formatting an invalid entity will result in an exception. You should make sure to validate it beforehand.
Person
Organization
Laravel validators
The package registrers the "entity" rule, which accepts the parameters any
, organization
or person
.
You may also omit the parameter and the validator will fallback to any
Custom messages
Implicit validation
For the validator to run when the social security/organizational number is missing or an empty string (note, does not apply to null
) you will need to implicitly state so with a required rule, i.e:
or
Attributes
Person
Attribute | Comment | type |
---|---|---|
ssn | The SSN of the entity | string |
century | Birthyear century | string |
year | Birthyear | string |
month | Birthmonth | string |
day | Birthday | string |
num | The "last four digits" | string |
check | The checksum verifier | string |
age | Age | string |
birthday | Entitys birthday | DateTime |
gender | Gender (Male/Female) | string |
type | Type of ssn * | string |
Either "Samordningsnummer" or "Personnummer"*
Example
Organization
Attribute | Comment | type |
---|---|---|
org_no | The org. no. of the entity | string |
check | The checksum verifier | string |
type | Type of organisation* | string |
One of the following: "Dödsbon", "Stat, landsting och kommuner", "Aktiebolag", "Enkelt bolag", "Ekonomiska föreningar", "Ideella föreningar och stiftelser" and "Handelsbolag, kommanditbolag och enkla bolag". Note: Organizations starting with 0, 3 and 4, while technically a valid number – it is uncertain if they exist, and will return and empty string.*
Example
Clean-helper
The Entity-class contains a clean-helper that can be useful for removing illegal characters from a social security- or organisational number:
Note that this is not automatically applied, so you will need to clean the string before validation.
Gotcha moments
Enskild firma
EF (Enskild firma) – while technically a company/organization, uses the proprietors personnummer. Therefore that number will not validate as company/organization. Instead of using a custom solution for this (as Creditsafe, Bisnode and others do – by adding additional numbers/characters to the organizational number/social security number), a way to handle this would be:
- Work with 10 digits when expecting both people and companies (preferably with a separator). Hint: both
Person
andOrganization
will format with 10 digits (and a separator) by default viaformat()
. - Use the
detect
-method to automatically validate both types
If you need to after the validation check type;
License
The MIT License (MIT). Please see the License File for more information.
© 2022 Marcus Olsson.