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.
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 beS,T,ForGdepending 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#and0000000.
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.
`
function nricVal(){
var ic=document.getElementByID("nric").value;
if(!ic.match(/^[STFG]\d{7}[A-Z]$/)){
alert("Invalid NRIC");
return false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With