选择显示字体大小

验证身份证号是否正确的代码

我们要验证身份证号是否正确,就得先了解身份证号的含意。

身份证号都代表什么意思?

1、号码的结构
公民身份号码是特征组合码,由十七位数字本体码和一位校验码组成。排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码。

2、地址码(前六位数)
表示编码对象常住户口所在县(市、旗、区)的行政区划代码,按gb/t2260的规定执行。

3、出生日期码(第七位至十四位)
表示编码对象出生的年、月、日,按gb/t7408的规定执行,年、月、日代码之间不用分隔符。

4、顺序码(第十五位至十七位)
表示在同一地址码所标识的区域范围内,对同年、同月、同日出生的人编定的顺序号,顺序码的奇数分配给男性,偶数分配给女性。

5、校验码(第十八位数)
(1)十七位数字本体码加权求和公式
s = sum(ai * wi), i = 0, ... , 16 ,先对前17位数字的权求和
ai:表示第i位置上的身份证号码数字值
wi:表示第i位置上的加权因子
wi: 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2
(2)计算模
y = mod(s, 11)
(3)通过模得到对应的校验码
y: 0 1 2 3 4 5 6 7 8 9 10
校验码: 1 0 x 9 8 7 6 5 4 3 2

所以我们就可以大致写一个函数来校验是否正确了。

 

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,1,1", ",")
if len(e) < 15 or len(e) = 16 or len(e) = 17 or len(e) > 18 then
'idcheck= "身份证号共有 15 码或18位"
idcheck = false
exit function
end if
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
'idcheck= "身份证除最后一位外,必须为数字!"
idcheck = false
exit function
end if
dim stryear, strmonth, strday
stryear = cint(mid(ai, 7, 4))
strmonth = cint(mid(ai, 11, 2))
strday = 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
'idcheck= "身份证输入错误!"
idcheck = false
exit function
end if
if strmonth > 12 or strday > 31 then
idcheck = false
'idcheck= "身份证输入错误!"
exit function
end if
else
'idcheck= "身份证输入错误!"
idcheck = false
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
strverifycode = arrverifycode(modvalue)
ai = ai & strverifycode
idcheck = ai
if len(e) = 18 and e <> ai then
'idcheck= "身份证号码输入错误!"
idcheck = false
exit function
end if
end function


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons