NRIC Utils

November 2020 | A module to validate and mask Singapore NRICs

LinksGitHub

NRIC utils is a library containing functions to validate and mask Singapore NRICs. I had originally created this library for my work in the Singapore Armed Forces.

The library contains functions to validate and mask Singapore NRICs:

const { maskNric, validateNric } = require('nric-utils');
// Or
import { maskNric, validateNric } from 'nric-utils';

const nric = 'S0000002G';

validateNric(nric); 
// => true

maskNric('S0000002G'); 
// => 002G

/* 
Pass in true to maskNric to also include the first letter:
*/
maskNric('S0000002G', true); 
// => S002G