-
-
Save coffeesam/f24a03fdefdcd413954b44dc1475f746 to your computer and use it in GitHub Desktop.
Revisions
-
coffeesam renamed this gist
Jun 11, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
coffeesam revised this gist
Jun 11, 2018 . 2 changed files with 40 additions and 38 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ //Based on http://www.samliew.com/icval/ const isNRIC = (str) => { if (str.length != 9) return false; str = str.toUpperCase(); let i; const icArray = []; for(i = 0; i < 9; i++) { icArray[i] = str.charAt(i); } icArray[1] = parseInt(icArray[1], 10) * 2; icArray[2] = parseInt(icArray[2], 10) * 7; icArray[3] = parseInt(icArray[3], 10) * 6; icArray[4] = parseInt(icArray[4], 10) * 5; icArray[5] = parseInt(icArray[5], 10) * 4; icArray[6] = parseInt(icArray[6], 10) * 3; icArray[7] = parseInt(icArray[7], 10) * 2; let weight = 0; for(i = 1; i < 8; i++) { weight += icArray[i]; } const offset = (icArray[0] == "T" || icArray[0] == "G") ? 4:0; const temp = (offset + weight) % 11; const st = ["J","Z","I","H","G","F","E","D","C","B","A"]; const fg = ["X","W","U","T","R","Q","P","N","M","L","K"]; let theAlpha; if (icArray[0] == "S" || icArray[0] == "T") { theAlpha = st[temp]; } else if (icArray[0] == "F" || icArray[0] == "G") { theAlpha = fg[temp]; } return (icArray[8] === theAlpha); } module.exports = isNRIC This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,38 +0,0 @@ -
eddiemoore revised this gist
Oct 24, 2013 . 1 changed file with 4 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ //Based on http://www.samliew.com/icval/ function validateNRIC(str) { if (str.length != 9) return false; @@ -30,11 +31,8 @@ function validateNRIC(str) { var fg = ["X","W","U","T","R","Q","P","N","M","L","K"]; var theAlpha; if (icArray[0] == "S" || icArray[0] == "T") { theAlpha = st[temp]; } else if (icArray[0] == "F" || icArray[0] == "G") { theAlpha = fg[temp]; } return (icArray[8] === theAlpha); } -
eddiemoore created this gist
Oct 24, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ function validateNRIC(str) { if (str.length != 9) return false; str = str.toUpperCase(); var i, icArray = []; for(i = 0; i < 9; i++) { icArray[i] = str.charAt(i); } icArray[1] = parseInt(icArray[1], 10) * 2; icArray[2] = parseInt(icArray[2], 10) * 7; icArray[3] = parseInt(icArray[3], 10) * 6; icArray[4] = parseInt(icArray[4], 10) * 5; icArray[5] = parseInt(icArray[5], 10) * 4; icArray[6] = parseInt(icArray[6], 10) * 3; icArray[7] = parseInt(icArray[7], 10) * 2; var weight = 0; for(i = 1; i < 8; i++) { weight += icArray[i]; } var offset = (icArray[0] == "T" || icArray[0] == "G") ? 4:0; var temp = (offset + weight) % 11; var st = ["J","Z","I","H","G","F","E","D","C","B","A"]; var fg = ["X","W","U","T","R","Q","P","N","M","L","K"]; var theAlpha; if (icArray[0] == "S" || icArray[0] == "T") { theAlpha = st[temp]; } else if (icArray[0] == "F" || icArray[0] == "G") { theAlpha = fg[temp]; } return icArray[8] != theAlpha ? false : true; }