Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression for NRIC/FIN in Singapore

Tags:

regex

I want to check the user input data for NRIC/FIN in Singapore is right or not.

Is [A-Z] [0-9]{7} [A-Z] the right regex? Do I need to check the first character being S/F/T/G? Please let me know if I need to check for other case.

Any ideas would be greatly appreciated. Thank You.

like image 733
Sandar Min Aye Avatar asked Dec 30 '25 13:12

Sandar Min Aye


2 Answers

It looks like this is what you are looking for:

^[STFG]\d{7}[A-Z]$

As per Wikipedia NRIC/FIN article.

The structure of the NRIC number/FIN is #0000000@ where:
# - This is a letter that can be S, T, F or G depending on the status of the holder.
0000000 - This is a 7 digit serial number assigned to the document holder
@ - This is the checksum letter calculated based on # and 0000000.

Perhaps, you would like to make it case-insensitive ((?i)^[STFG]\d{7}[A-Z]$).

Also, if you want to validate that code further, checking if it is a foreigner's or Singapore citizen's ID, you'd need a different regex.

like image 172
Wiktor Stribiżew Avatar answered Jan 01 '26 09:01

Wiktor Stribiżew


`

function nricVal(){
    var ic=document.getElementByID("nric").value;
    if(!ic.match(/^[STFG]\d{7}[A-Z]$/)){
       alert("Invalid NRIC");
       return false;
    }  
}
like image 23
Murugesh Avatar answered Jan 01 '26 09:01

Murugesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!