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.
<?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