PHP 精確驗證身份證號

2021-07-14 12:39:03 字數 2252 閱讀 4455

<?php 

// check

class check

// 是數值

if(is_numeric($num))else

}elseelse

// 省市縣(6位)

$areanum = substr($num,0,6);

// 出生年月(8位)

$datenum = substr($num,6,8);

// 性別(3位)

$***num = substr($num,14,3);

// 校驗碼(1位)

$endnum = substr($num,17,1);

if($endnum != 'x' && $endnum != 'x')}}

if(isset($areanum))

}if(isset($datenum))

}// 性別1為男,2為女

if($check*** == 1)

}}else if($check*** == 2)}}

if(isset($endnum))

}return true;

}// 驗證城市

private function checkarea($area)else

//**********==

// 對市 區進行驗證

//**********==

}// 驗證出生日期

private function checkdate($date)elseelse

}if(0<$date2 && $date2 <13)else

}elseelse

}}elseelse

}}else

}// 驗證性別

private function check***($***)else

}// 驗證18位身份證最後一位

private function checkend($end,$num)

$checkhouparameter= $sum % 11;

if($checkhou[$checkhouparameter] != $num[17])else

}// 驗證平年潤年,引數年份,返回 true為潤年 false為平年

private function checky($y)

if($y % 100 == 0)else

}else if($y % 4 == 0)else

}// 當月天數 引數月份(不包括2月) 返回天數

private function getdatenum($month)else if($month == 2)else

} }// 測試

header("content-type:text/html;charset=utf-8");

$num = '350322199001282536';

// 1為男,2為女,不輸入為不驗證

$*** = 1;

$test = new check();

$data = $test ->checkidentity($num,$***);

var_dump($data);

// 新的18位身份證號碼各位的含義:

// 1-2位省、自治區、直轄市**; 11-65

// 3-4位地級市、盟、自治州**;

// 5-6位縣、縣級市、區**;

// 7-14位出生年月日,比如19670401代表2023年4月1日;

// 15-17位為順序號,其中17位男為單數,女為雙數;

// 18位為校驗碼,0-9和x,由公式隨機產生。

// 舉例:

// 130503 19670401 0012這個身份證號的含義: 13為河北,05為邢台,03為橋西區,出生日期為2023年4月1日,順序號為001,2為驗證碼。

// 15位身份證號碼各位的含義:

// 1-2位省、自治區、直轄市**;

// 3-4位地級市、盟、自治州**;

// 5-6位縣、縣級市、區**;

// 7-12位出生年月日,比如670401代表2023年4月1日,這是和18位號碼的第乙個區別;

// 13-15位為順序號,其中15位男為單數,女為雙數;

// 與18位身份證號的第二個區別:沒有最後一位的驗證碼。

// 舉例:

// 130503 670401 001的含義; 13為河北,05為邢台,03為橋西區,出生日期為2023年4月1日,順序號為001。

身份證號驗證

原文 身份證號驗證 public static boolean isidnumber string idnumber 定義判別使用者身份證號的正規表示式 15位或者18位,最後一位可以為字母 string regularexpression 1 9 d 18 19 20 d 0 1 9 10 11 ...

身份證號驗證

身份證號組成 17位數字 1位校驗碼 位址碼 前六位 出生日期碼 第七位至第十位 順序碼 第十五位至十七位 對同年同月同日生的人便定的順序號,順序號奇數為男生,偶數為女生 檢驗碼 第十八位 0 9 x var acity function iscarid sid d x i.test sid ret...

js 身份證號驗證

function iscardid sid var isum 0 var info if d d x i.test sid return 身份證長度或格式錯誤 sid sid.replace x i,a if acity parseint sid.substr 0,2 null return 身份證...