/**
* 验证其他身份证号,港澳台身份证
* @param $IDCard
* @return bool
*/
public static function checkOtherIDCard($IDCard)
{
$IDCard = strtoupper($IDCard);
$IDCard = str_replace(array(‘(‘, ‘)‘), array(‘(‘, ‘)‘), $IDCard);
preg_match(‘/^([A-Z])([\d]{6})\(([A\d])\)$/‘, $IDCard, $hongkong);//香港
if ($hongkong && count($hongkong) === 4) {
$sum = (ord($hongkong[1]) - 64) * 8;
$index = 7;
for ($j = 0; $j < 6; $j++) {
$sum += $hongkong[2]{$j} * $index;
$index--;
}
$get_num = $sum % 11;
if ($get_num === 1) {
$get_num = ‘A‘;
} elseif ($get_num > 1) {
$get_num = 11 - $get_num;
}
if ($hongkong[3] === $get_num) {
return true;
}
return false;
}
preg_match(‘/^([A-Z])([\d]{9})$/‘, $IDCard, $*);//中国*省
if ($* && count($*) === 3)//首位数字代表性别,男性为1、女性为2
{
$area_code = array(‘A‘ => 10, ‘B‘ => 11, ‘C‘ => 12, ‘D‘ => 13, ‘E‘ => 14, ‘F‘ => 15, ‘G‘ => 16, ‘H‘ => 17, ‘I‘ => 34, ‘J‘ => 18, ‘K‘ => 19, ‘L‘ => 20, ‘M‘ => 21, ‘N‘ => 22, ‘O‘ => 35, ‘P‘ => 23, ‘Q‘ => 24, ‘R‘ => 25, ‘S‘ => 26, ‘T‘ => 27, ‘U‘ => 28, ‘V‘ => 29, ‘W‘ => 32, ‘X‘ => 30, ‘Y‘ => 31, ‘Z‘ => 33);
$code = $area_code[$*[1]];
$sum = $code{0} + $code{1} * 9;
$index = 8;
for ($k = 1; $k < 8; $k++) {
$sum += $*[2]{$k} * $index;
$index--;
}
$get_num = $sum % 10;
if ($get_num === $*[2]{8}) {
return true;
}
return false;
}
preg_match(‘/^[157][\d]{6}\([\d]\)$/‘, $IDCard, $aomen);//澳门
if ($aomen) {
return true;
}
return false;
}
php 验证港澳台身份证