Finnish Social Security number validator.
This simple class validates social security numbers and provides methods for checking birthdate, age and gender based on the 'hetu'.
- PHP >= 8.0
The recommended way is to install the lib through Composer.
composer require devsmo/php-hetu
Or you can add this to your composer.json
{
"require": {
"devsmo/php-hetu": "^1.0"
}
}The hetu class creates an immutable value object. You can initialize the object in two ways:
<?php
$hetu = Devsmo\Hetu::create('041281-981T');
if ( $hetu ) {
echo "It's valid";
}
else {
echo "It's not valid...";
}Or if you want to catch possible errors:
<?php
try {
$hetu = new Devsmo\Hetu('041281-981T');
}
catch (\InvalidArgumentException $e){
$msg = $e->getMessage();
}The class has three methods:
<?php
$age = $hetu->getAge(); // 35
$date_of_birth = $hetu->getDateStr(); // 1981-12-04
$gender = $hetu->getGender(); // maleFeel free to contribute! Just create a new issue or a new pull request.
This library is released under the MIT License.