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

This package is auto-updated.

Last update: 2024-10-24 04:04:04 UTC


README

Latest version GitHub Workflow Status PHP version Codecov Mutation testing badge Downloads License

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