ion-bazan / nric
Provides a value object to store, generate and validate Singapore NRIC/FIN numbers, including new M-series FIN numbers
v1.0.2
2022-05-20 02:48 UTC
Requires
- php: >= 7.4
- symfony/polyfill-php80: ^1.22
Requires (Dev)
- phpunit/phpunit: ^9.4
README
It now supports new 2022 M-series FIN numbers!
This package provides a self-validating value object for storing, generating and validating Singapore NRIC and FIN numbers in PHP.
Usage
<?php use IonBazan\NRIC\Exception\InvalidChecksumException; use IonBazan\NRIC\Exception\InvalidFormatException; use IonBazan\NRIC\NRIC; $nric = NRIC::generateNric(new DateTime('1990-01-01')); // Generate a random NRIC number $fin = NRIC::generateFin(new DateTime('1990-01-01')); // Generate a random FIN number try { $invalid = NRIC::fromString('S0000001A'); // Create a self-validating (invalid) instance } catch (InvalidChecksumException|InvalidFormatException $e) { var_dump('invalid'); } $valid = NRIC::fromString('S0000001I'); // Create a self-validating instance from valid input var_dump($valid->__toString()); // Thanks to Stringable interface