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 whether the birthday date is correct
{
return FALSE;
}
Else
{
Verify that the check code for the 18-digit ID is correct.
The check digit is generated according to ISO 7064:1983.mod 11-2, and 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, 4, 2);
$arr _ch = Array (' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 ');
$sign = 0;
for ($i = 0; $i < $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;
}
}
}
}
php--a function to verify that the ID card is valid