关于身份证验证系统的一点奇怪的问题。
我已经做好了系统的界面 初步实施验证功能 从网上搞了一些可用的身份证试了下 发现个奇怪的问题 我实在不知道怎么解决了
向各位大牛求救。看几幅图先
姑且不论他是否是个真人的东西,反正它通过了校验 检验码应该是对的
那我先把最后的校验位改为9 在我的程序上运行
可以看到第4个报错, 但是我改回X后确还是这样
为什么还是说第4项错误 确报校验码是X呢?
我的程序如下 有兴趣帮看下
程序代码:Clear All
Public gn_HalfWndHeight as Integer && 一半窗口高度
Public gn_HalfWndWidth as Integer && 一半窗口宽度
Public gn_Space, tb_W, tb_H as Integer && 控件间距 及 容器里的TextBox的高度宽度参数
gn_HalfWndHeight = 290
gn_HalfWndWidth = 400
gn_Space = 20
tb_W = 300
tb_H = 50
Public Dsc as Character
Dsc = "" && 检验结果信息字符串
Public gn_sum && 识别校验码时用于累加和取模
Public ga_Ctnr[8] &&容器数组
ga_Ctnr[1] = CreateObject("C_Struct", "Number", "身份证号码:", tb_W , tb_H, .T., "检验")
ga_Ctnr[2] = CreateObject("C_Struct", "Province", "省(直辖市):", tb_W , tb_H, .T., "重新输入")
ga_Ctnr[3] = CreateObject("C_Struct", "Area", "地区:", tb_W , tb_H, .T., "批量检验")
ga_Ctnr[4] = CreateObject("C_Struct", "City", "市(县):", tb_W , tb_H, .T., "退出")
ga_Ctnr[5] = CreateObject("C_Struct", "Date", "出生年月日:", tb_W , tb_H, .T., "注意事项")
ga_Ctnr[6] = CreateObject("C_Struct", "Sex", "性别:", tb_W , tb_H, .T., "版本说明")
ga_Ctnr[7] = CreateObject("C_Struct", "Address", "户籍所在地:", tb_W + 100, tb_H, .F.,"33")
ga_Ctnr[8] = CreateObject("C_Struct", "Result", "检验结果:", tb_W + 200, tb_H * 2, .F.,"33")
Main()
Clear All
Return
Procedure Main() && 主函数
Local lo_MainForm
lo_MainForm = NewObject("C_Form")
lo_MainForm.show
Read EVENTS
Return
EndProc
Function CheckID() && 检验身份证号码函数
PARAMETER Src && Src为输入的身份证号码字符串
md11 = "0709100508040201060307091005080402" &&与身份证前17位相对应的索引对11的模
chk_Str ="10X98765432" &&校验码
Src = Alltrim(Src) && 去掉头尾空格和0
* 长度及出生日期的处理,仅仅接受15位和18位的身份证号码
Do Case
Case Len(Src) = 15
Src = Left(Src, 6) + "19" + Substr(Src, 7)
Case Len(Src) = 18
Src = Left(Src, 17)
Otherwise
Dsc_Len = "身份证的位数不正确!" + Chr(13) + "请重新输入!"
Src = "F"
Dsc = Dsc_Len
EndCase
If Src # "F"
* 身份证前17位必须是数字
For i = 1 to 17
If !IsDigit(Substr(Src, i, 1))
Dsc_char = "1: 身份证中含有非法字符" + Chr(13)
Else
Dsc_char = "1(非法字符): 此项合法" + Chr(13)
EndIf
EndFor
* 前两位是否在省级区划内
If !Left(Src, 2)$"11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45," +;
"46,50,51,52,53,54,61,62,63,64,65,71,81,82"
Dsc_div = "2: 身份证的所属省份非法" + Chr(13)
Else
Dsc_div = "2(所属省份): 此项合法" + Chr(13)
EndIf
* 检验出生年月日的合法性
If Empty(Date(Val(Substr(Src, 7, 4)), Val(Substr(Src, 11, 2)), Val(Substr(Src, 13, 2))))
Dsc_ymd = "3: 身份证包含的日期非法" + Chr(13)
Else
Dsc_ymd = "3(出生日期): 此项合法" + Chr(13)
EndIf
* 检验最后一位校验码是否匹配
gn_sum = 0
For i = 1 to 17
gn_sum = gn_sum + Val(Substr(Src, i, 1)) * Val(Substr(md11, 2 * i - 1, 2))
EndFor
gn_sum = Mod(gn_sum, 11)
If Right(Src, 1) != Substr("10X98765432", gn_sum + 1, 1)
Dsc_Chk = "4: 身份证的校验码错误,校验码应为:" + Substr("10X98765432", gn_sum + 1, 1)
Else
Dsc_Chk = "4(校验码): 此项合法"
EndIf
Dsc = Dsc_char + Dsc_div + Dsc_ymd + Dsc_Chk
EndIf
Return Dsc
EndFunc
* 定义一个结构体存放和全局数组相对应的参数
Define Class C_Struct as Custom
ID = ""
lbl_Caption = ""
chg_Width = 0
chg_Height = 0
ask_Button = .T.
btn_Caption = ""
Procedure Init(tc_ID, tc_lbl_Caption, tn_chg_Width, tn_chg_Height, tb_ask_Button, tc_btn_Caption)
With This
.ID = tc_ID
.lbl_Caption = tc_lbl_Caption
.chg_Width = tn_chg_Width
.chg_Height = tn_chg_Height
.ask_Button = tb_ask_Button
.btn_Caption = tc_btn_Caption
EndWith
EndProc
EndDefine
* 定义容器类 包含三个控件:Label, TextBox, CommandButton
Define Class C_Container as Container
BorderWidth = 2
SpecialEffect = 1
Width = 2 * (gn_HalfWndWidth - gn_Space)
ID = ""
Add Object Ctnr_Label as Label with ;
Left = gn_Space,;
Height = 40,;
Width = 150
Add Object Ctnr_Text as TextBox with ;
Height = 50,;
Width = 350,;
Left = This.Ctnr_Label.Left + This.Ctnr_Label.Width + 30,;
Top = 0
Add Object Ctnr_Button as CommandButton with ;
Height = 40,;
Width = 150,;
Left = This.Ctnr_Text.Left + This.Ctnr_Text.Width + 10,;
BackColor = Rgb(255, 0, 0)
Procedure Init
With This
.Height = .Ctnr_Text.Height
.Ctnr_Label.Top = .Ctnr_Text.Height / 2 - .Ctnr_Label.Height / 2
.Ctnr_Button.Top = .Ctnr_Text.Height / 2 - .Ctnr_Label.Height / 2
.SetAll("Visible", .T.)
.SetAll("FontSize", 16)
.SetAll("Alignment", 2)
.SetAll("FontBold", 1)
EndWith
EndProc
EndDefine
* 定义主窗口类 在其中添加8个C_Container容器对象
Define Class C_Form as Form
MaxButton = .F.
Caption = "身份证号检验系统"
AutoCenter = .T.
ShowWindow = 2
BorderStyle = 2
* 添加系统名标签
Add Object lo_Caption as Label with ;
Top = 10,;
Caption = "身份证号检验系统",;
FontSize = 20,;
AutoSize = .T. ,;
FontName = "楷体"
* 添加容器类对象
Add Object lo_Number01 as C_Container
Add Object lo_Number02 as C_Container
Add Object lo_Number03 as C_Container
Add Object lo_Number04 as C_Container
Add Object lo_Number05 as C_Container
Add Object lo_Number06 as C_Container
Add Object lo_Number07 as C_Container
Add Object lo_Number08 as C_Container
* 初始化对系统标题标签的位置
Procedure lo_Caption.Init
With This
.Left = gn_HalfWndWidth - .Width / 2
EndWith
EndProc
* 主窗口类初始化
Procedure Init
Local chg_Top, ln_sp, ln_Top as Integer
chg_Top = 0
ln_sp = 5
ThisForm.Top = 50
ThisForm.Left = 50
ThisForm.Height = 2 *gn_HalfWndHeight
ThisForm.Width = 2 * gn_HalfWndWidth
For i = 1 to Alen(ga_Ctnr, 1) && 循环添加 用全局数组来赋值
lc_Name = "lo_Number" + Padl(i, 2, '0')
With This.&lc_Name
If i == 1
ln_Top = ThisFOrm.lo_Caption.Top + ThisForm.lo_Caption.Height + gn_Space
Else
ln_Top = ln_Top + ga_Ctnr[i - 1].chg_Height + ln_sp
EndIf
.Top = ln_Top
.Left = gn_Space
.Ctnr_Label.Caption = ga_Ctnr[i].lbl_Caption
.Ctnr_Button.Caption = ga_Ctnr[i].btn_Caption
.Ctnr_Text.Width = ga_Ctnr[i].chg_Width
.Ctnr_Text.Height = ga_Ctnr[i].chg_Height
.Height = ga_Ctnr[i].chg_Height
If ga_Ctnr[i].ask_Button == .F.
.Ctnr_Button.Visible = .F.
EndIf
If i == 8 .or. i == 1
.Ctnr_Text.Alignment = 0
EndIf
EndWith
EndFor
EndProc
* 检验按钮的点击事件处理
Procedure lo_Number01.Ctnr_Button.Click
Src = Alltrim(ThisForm.lo_Number01.Ctnr_Text.Value)
Dsc = CheckID(Src)
ThisForm.lo_Number08.Ctnr_Text.Value = Dsc
EndProc
* 退出窗口
Procedure Destroy
Clear Events
EndProc
EndDefine
放一百分 求救。。。








