devsmo / php-hetu
PHP Hetu validator. Hetu stands for Henkilötunnus aka Finnish Social Security Number
Installs: 140 618
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=8.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is not auto-updated.
Last update: 2025-06-23 16:43:59 UTC
README
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'.
Requirements
- PHP >= 8.0
Installation
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" } }
Usage
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(); // male
Contribution
Feel free to contribute! Just create a new issue or a new pull request.
License
This library is released under the MIT License.