学习网考试学习资料

Gzu521.com

用ASP编写函数实现身份证验证代码

ASP教程   点击:次   发布时间:2005-11-25   【字体: 】   来源:51cto
Gzu521.com我的学习网
 

function checkcardid(e)

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,1,1", ",")

if len(e) < 15 or len(e) = 16 or len(e) = 17 or len(e) > 18 then

checkcardid= "身份证号共有 15 码或18位"

checkcardid = false

exit function

end if 3'n,Waym='Y_=') [ 本 资 料 来 源 于 贵 州 学 习 网 网络编程ASP教程 http://Www.gzU521.com ] 3'n,Waym='Y_=')

dim ai

if len(e) = 18 then

ai = mid(e, 1, 17)

elseif len(e) = 15 then

ai = e

ai = left(ai, 6) & "19" & mid(ai, 7, 9)

end if

if not isnumeric(ai) then

checkcardid= "身份证除最后一位外,必须为数字!"

exit function

end if

dim stryear, strmonth, strday

tryear = cint(mid(ai, 7, 4))

trmonth = cint(mid(ai, 11, 2))

trday = cint(mid(ai, 13, 2))

birthday = trim(stryear) + "-" + trim(strmonth) + "-" + trim(strday)

if isdate(birthday) then

if datediff("yyyy",now,birthday) <-140 or cdate(birthday)> date() then

checkcardid= "身份证输入错误!"

exit function

end if

if strmonth > 12 or strday > 31 then

checkcardid= "身份证输入错误!"

exit function

end if

else

checkcardid= "身份证输入错误!"

exit function

end if

dim i, totalmulaiwi

for i = 0 to 16

totalmulaiwi = totalmulaiwi + cint(mid(ai, i + 1, 1)) * wi(i)

next

dim modvalue

modvalue = totalmulaiwi mod 11

dim strverifycode

trverifycode = arrverifycode(modvalue)

ai = ai & strverifycode

checkcardid = ai

if len(e) = 18 and e <> ai then

checkcardid= "身份证号码输入错误!"

exit function

end if

end function

response.write checkcardid("528337194801020025")

责任编辑:gzu521

网络编程分类
ASP教程
.Net教程
Java教程
PHP教程
数据库基础
ACCESS教程
SQL Server教程
MySQL教程
Oracle教程
分类推荐信息
更多...
大类最新文章
更多...