excel vba 身份证校验
来源:互联网 发布:呼不停软件 编辑:程序博客网 时间:2024/06/05 14:52
身份证18位分别代表的含义,身份证15位升级到18位,原来年用2位且没有最后一位,从左到右方分别表示
①1-2 升级行政区代码
②3-4 地级行政区划分代码
③5-6 县区行政区分代码
④7-10 11-12 13-14 出生年、月、日
⑤15-17 顺序码,同一地区同年、同月、同日出生人的编号,奇数是男性,偶数是女性
⑥18 校验码,如果是0-9则用0-9表示,如果是10则用X(罗马数字10)表示
身份证号码编码规则及校验位校验算法
Function isValidPersionID(sfz As String) As Boolean Dim yy As Integer Dim mm As Integer Dim dd As Integer Dim i As Integer Dim iPidLen As Integer Dim arPidWeight Dim arPidCheck Dim lCheckSum As Long isValidPersionID = False iPidLen = Len(sfz) If iPidLen <> 18 And iPidLen <> 15 Then this.Text = "#VALUE!" '在表格中写入#VALUE!,以下部分都可以参照 Exit Function End If arPidWeight = Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)'权重 arPidCheck = Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2")'所有值 lCheckSum = 0 For i = 1 To 15If InStr("0123456789", Mid(sfz, i, 1)) = 0 Then Exit Function lCheckSum = lCheckSum + CInt(Mid(sfz, i, 1)) * arPidWeight(i - 1) Next i If iPidLen = 15 Then yy = CInt(Mid(sfz, 7, 2)) + 1900 mm = CInt(Mid(sfz, 9, 2)) dd = CInt(Mid(sfz, 11, 2)) Else yy = CInt(Mid(sfz, 7, 4)) mm = CInt(Mid(sfz, 11, 2)) dd = CInt(Mid(sfz, 13, 2))Then Exit Function If InStr("0123456789", Mid(sfz, 17, 1)) = 0 Then Exit Function If InStr("0123456789X", UCase(Mid(sfz, 18, 1))) = 0'转成大写字母 Then Exit FunctionlCheckSum = lCheckSum + CInt(Mid(sfz, 16, 1)) * arPidWeight(15) lCheckSum = lCheckSum + CInt(Mid(sfz, 17, 1)) * arPidWeight(16) lCheckSum = lCheckSum Mod 11 If UCase(Mid(sfz, 18, 1)) <> arPidCheck(lCheckSum)'转成大写字母 Then Exit Function End If If Not isValidDate(yy, mm, dd) Then Exit Function isValidPersionID = True End FunctionFunction isValidDate(yy As Integer, mm As Integer, dd As Integer) As Boolean isValidDate = False If yy > 2200 Or yy < 1900 Then Exit Function If mm > 12 Or mm < 1 Then Exit Function If dd < 1 Then Exit Function If (mm = 1 Or mm = 3 Or mm = 5 Or mm = 7 Or mm = 8 Or mm = 10 Or mm = 12) And dd > 31 Then Exit Function If (mm = 4 Or mm = 6 Or mm = 9 Or mm = 11) And dd > 30 Then Exit Function If yy Mod 4 = 0 Then If mm = 2 And dd > 29 Then Exit Function Else If mm = 2 And dd > 28 Then Exit Function End If isValidDate = TrueEnd Function
1 0
- excel vba 身份证校验
- 身份证校验
- 身份证校验
- 身份证校验
- 身份证校验
- 身份证校验
- 身份证校验
- 身份证校验
- 身份证校验
- 身份证校验
- 身份证校验
- 身份证校验
- 身份证校验
- 校验身份证
- 身份证校验
- Javascript身份证校验(原创)
- 身份证校验[pb源码]
- JS 身份证校验函数
- HDU 3068 最长回文
- 计算机图形学-实验5-掌握Bezier样条曲面生成思想、复习基本图元绘制、交互操作和几何变换相关内容
- SDIO驱动(4)sdio总线上driver和设备的match
- 常用命令
- 部署Servlet(一)——Servlet2.X
- excel vba 身份证校验
- Java事务处理全解析(六)—— 使用动态代理(Dynamic Proxy)完成事务
- 杨辉三角 算法
- 使用自定义注解向servlet注入spring bean
- android菜鸟练手小项目之自定义日历,涵盖LitePal数据库,极光推送(二)
- Java IO流(三) 流转换和流操作的基本规律
- maven工程转web工程
- android菜鸟练手小项目之自定义日历,涵盖LitePal数据库,极光推送(三)
- Python学习笔记--4