Created
June 7, 2016 16:17
-
-
Save cmariod/61ecb5a025d48e838b7920f900d76de2 to your computer and use it in GitHub Desktop.
Revisions
-
cmariod created this gist
Jun 7, 2016 .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,45 @@ <?php class Nric_validation{ function is_NRIC($nric) { if(strlen($nric)==9) // NRIC is alway 9 Digits { $nric = strtoupper($nric); $prefix = substr($nric,0,1); $postfix = substr($nric,8,1); $ic_number = substr($nric,1,7); $num = 0; $weight = array(2,7,6,5,4,3,2); $lookup['S'] = array('J','Z','I','H','G','F','E','D','C','B','A'); $lookup['T'] = array('G','F','E','D','C','B','A','J','Z','I','H'); $lookup['F'] = array('X','W','U','T','R','Q','P','N','M','L','K'); $lookup['G'] = array('R','Q','P','N','M','L','K','X','W','U','T'); for($i=0;isset($weight[$i]);$i++) { $num+=substr($ic_number,$i,1)*$weight[$i]; } $num %= 11; if (isset($lookup[$prefix])) { if($lookup[$prefix][$num] == $postfix) { return true; } else { return false; } } else { return false; } } } }