1
、簡單的正規表示式:(1
)preg_match(
"/^(/d|/d|/dx)$/
",$id_card) (2
)preg_match(
"/^(/d)(18|19|20)?(/d)([01]/d)([0123]/d)(/d)(/d|x)?$/
",$id_card) (3
)preg_match(
"/(^/d$/)|(/d(?:/d|x|x)$/),$id_card)
2、複雜並且嚴格一些的驗證:
//這個可以驗證15位和18位的身份證,並且包含生日和校驗位的驗證。
//如果有興趣,還可以加上身份證所在地的驗證,就是前6位有些數字合法有些數字不合法。
function isidcardno(num) $)|
(^/d([0-
9]|x)$)
/.test(num))) //
校驗位按照iso 7064:1983.mod 11-2的規定生成,x可以認為是數字10。
//下面分別分析出生日期和校驗位
var len, re;
len
=num.length;
if(len
==15
) )(/d)(/d)(/d)(/d)$
/);
var arrsplit
=num.match(re);
//檢查生日日期是否正確
var dtmbirth
=new
date('19
'+arrsplit[2]
+'/'
+arrsplit[3]
+'/'
+arrsplit[
4]);
var bgoodday;
bgoodday
=(dtmbirth.getyear()
==number(arrsplit[
2]))
&&((dtmbirth.getmonth() +1
) ==
number(arrsplit[
3]))
&&(dtmbirth.getdate()
==number(arrsplit[
4])); if(
!bgoodday)
else
num
+=arrch[ntemp %11
];
return
num;
}
} if
(len
==18
) )(/d)(/d)(/d)(/d)([0-
9]|x)$
/);
var arrsplit
=num.match(re);
//檢查生日日期是否正確
var dtmbirth
=new
date(arrsplit[2]
+"/"
+arrsplit[3]
+"/"
+arrsplit[
4]);
var bgoodday;
bgoodday
=(dtmbirth.getfullyear()
==number(arrsplit[
2]))
&&((dtmbirth.getmonth() +1
) ==
number(arrsplit[
3]))
&&(dtmbirth.getdate()
==number(arrsplit[
4])); if(
!bgoodday)
else
valnum
=arrch[ntemp %11
]; if
(valnum
!=num.substr(
17,
1))
return
num;
} }
return
false
; }
3、嚴格的驗證:
<
script
>
var acity
=function cidinfo(sid)(d
|x)$
/i.test(sid))
return
false
;sid
=sid.replace(/x$
/i,"a
");if(acity[parseint(sid.substr(0,
2))]
==null
)return
"error:非法地區";
sbirthday
=sid.substr(6,
4)+"
-"+number(sid.substr(10,
2))+"
-"+number(sid.substr(12,
2));
var d
=new
date(sbirthday.replace(
/-/g,"/
"))if(sbirthday
!=(d.getfullyear()+"
-"+(d.getmonth()+1
) +"-
"+d.getdate()))
return
"error:非法生日";
for(var i =17
;i>=
0;i
--) isum
+=(math.pow(
2,i) %11
) *parseint(sid.charat(17-
i),11)if
(isum%11
!=1)return
"error:非法證號";
return
acity[parseint(sid.substr(0,
2))]+"
,"+sbirthday+"
,"+(sid.substr(16,
1)%2
?"男"
:"女"
)}document.write(cidinfo(
"380524198002300016"),
" ");document.write(cidinfo(
"340524198002300019"),
" ")document.write(cidinfo(
"340524197711111111"),
" ")document.write(cidinfo(
"34052419800101001x"),
" ");script
>
身份證驗證
身份證分為兩類 1 全是數字 15位或者18位。2 大寫x 18位,最後一位字母x,其餘必需是數字。正則 d d d d x 身份驗證例項 header content type text html charset utf 8 idc post idc bm substr idc,0,6 gende...
身份證驗證指令碼
function checkidcard idcard var idcard,y,jym var s,m var idcard array new array idcard array idcard.split 地區檢驗 if area parseint idcard.substr 0,2 null...
ASP身份證驗證
function idcheck e idcheck true arrverifycode split 1,0,x,9,8,7,6,5,4,3,2 wi split 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 checker split 1,9,8,7,6,5,4,3,2...