【www.bbyears.com--php常用代码】
代码如下
/**
* 判断是否为合法的身份证号码
* @param $mobile
* @return int
*/
functionisCreditNo($vStr){
$vCity=array(
ཇ',',ཉ',ཊ',ཋ',ད',དྷ',
ན',ཛ',ཛྷ',ཝ',ཞ',ཟ',འ',
ཡ',ཥ',ས',ཧ',ཨ',ཀྵ',ཪ',
',',',ཱ',ི',ཹ',ེ',
ཻ',ོ',ཽ',ྃ',ྍ',ྎ',ྗ'
);
if(!preg_match('/^([\d]{17}[xX\d]|[\d]{15})$/',$vStr))returnfalse;
if(!in_array(substr($vStr, 0, 2),$vCity))returnfalse;
$vStr= preg_replace('/[xX]$/i','a',$vStr);
$vLength=strlen($vStr);
if($vLength== 18) {
$vBirthday=substr($vStr, 6, 4) .'-'.substr($vStr, 10, 2) .'-'.substr($vStr, 12, 2);
}else{
$vBirthday=ཏ'.substr($vStr, 6, 2) .'-'.substr($vStr, 8, 2) .'-'.substr($vStr, 10, 2);
}
if(date('Y-m-d',strtotime($vBirthday)) !=$vBirthday)returnfalse;
if($vLength== 18) {
$vSum= 0;
for($i= 17 ;$i>= 0 ;$i--) {
$vSubStr=substr($vStr, 17 -$i, 1);
$vSum+= (pow(2,$i) % 11) * (($vSubStr=='a') ? 10 :intval($vSubStr, 11));
}
if($vSum% 11 != 1)returnfalse;
}
returntrue;
}