Function is_idcard ( $id ) { $id = strtoupper ($id); $regx = "/(^\d{15}$) | (^\d{17} ([0-9]| X) $)/"; $arr _split = array (); if (!preg_match ($REGX, $id)) { return FALSE; } if (15==strlen ($id)) //Check 15-bit { $regx = "/^ (\d{6}) + (\d{2}) + (\d{2}) + (\d{2}) + (\d{3}) $/"; @preg_match ($regx, $id, $arr _split); //Check that the birthday date is correct $dtm _birth = "$arr _split[2] . '/' . $arr _split[3]. '/' . $arr _split[4]; if (!strtotime ($dtm _birth)) { return false; } else { return TRUE; } } else //Check 18-bit { $regx = "/^ (\d{6}) + (\d{4}) + (\d{2}) + (\d{2}) + (\d{3}) ([0-9]| X) $/"; @preg_match ($regx, $id, $arr _split); $dtm _birth = $arr _split[2] . '/' . $ arr_split[3]. '/' . $arr _split[4]; if (!strtotime ($dtm _ Birth) //Check that the birthday date is correct &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;{&NBsp; return false; } else { // Verify that the check code for the 18-digit ID is correct. //check digit according to iso 7064:1983.mod 11-2 of the rules generated, X can be considered the number 10. $arr _int = array (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, &NBSP;4,&NBSP;2); $arr _ch = Array (' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 ') ; $sign = 0; for ( $i = 0; $i < 17; $i ++ ) { $b = (int) $id {$i}; $w = $arr _int[$i]; $sign += $b * $w; } $n = $sign % 11; $val _num = $arr _ch[$n]; if ($val _num != substr ($id, 17, 1)) { return FALSE; } else { return TRUE; } } }}
ID Card Verification