/** * 校驗身份證號碼是否合法
* @param $str
* @param bool $getbasicinfo 是否提取身份證號碼中的基本資訊(出生日期/性別)
* @return mixed
*/public
static function regexpmatchidcard($str, $getbasicinfo = false
) (18|19|20)?\d(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d(\d|[xx])$/";
preg_match($pattern, $str, $match);
$result = $match ? true : false
;
if (!$result)
//校驗前兩位是否是所有省份**
$province_code = ['
11', '
12', '
13', '
14', '
15', '
21', '
22', '
23', '
31', '
32', '
33', '
34', '
35', '
36', '
37', '
41', '
42', '
43', '
44', '
45', '
46', '
50', '
51', '
52', '
53', '
54', '
61', '
62', '
63', '
64', '
65', '
71', '
81', '
82', '91'
];
if (!in_array(substr($str, 0, 2
), $province_code))
//校驗身份證最後一位
$ahead17_char = substr($str, 0, 17
); $last_char = substr($str, -1
); $factor = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); //
前17位的權重
$c = array(1, 0, '
x', 9, 8, 7, 6, 5, 4, 3, 2); //
模11後的對應校驗碼
$t_res = 0
;
for ($i = 0; $i < 17; $i++)
$calc_last_char = $c [$t_res % 11
];
if ($last_char !=$calc_last_char)
if (!$getbasicinfo)
//從身份證號碼中提取出生日期和性別
$birth_year = substr($str, 6, 4
); $birth_month = substr($str, 10, 2
); $birth_day = substr($str, 12, 2
);
if (!checkdate($birth_month, $birth_day, $birth_year))
$brithday = $birth_year . "
-" . $birth_month . "-"
. $birth_day;
$gender_char = substr($str, -2, 1
);
if ($gender_char % 2 == 0
) else
return
[
'birthday
' =>$brithday,
'age
' =>self::getage(strtotime($brithday)),
'gender
' =>$gender,];}
/*** 根據出生日期獲取年齡
* @param string $birthday 出生日期時間戳
* @return false|string
*/public
static
function getage($birthday)
return
$age;
}
身份證號碼校驗
中國居民身份證號碼編碼規則 中國居民身份證校驗碼演算法 都包含 author liuwei date 2020 11 19 身份證校驗工具 public class idnumutil 定義判別使用者身份證號的正規表示式 15位或者18位,最後一位可以為字母 string regularexpres...
JAVA 驗證身份證號碼是否合法
public static boolean isidnumber string idnumber 定義判別使用者身份證號的正規表示式 15位或者18位,最後一位可以為字母 string regularexpression 1 9 d 18 19 20 d 0 1 9 10 11 12 0 2 1 9...
Oracle 身份證號碼校驗
今天來了身份證校驗的需求,想在oracle中校驗後將錯誤資料查詢出來。於是我在網上查到了身份證校驗的oracle函式。但是發現一些正確的身份證號也未校驗通過!後來經過千辛萬苦的努力終於發現了,網上給的函式中判斷是否是閏年的 substrb 函式應該從第7為開始擷取,而不是第6位!還有要注意最後一位校...