身份证号真实性效验VB源代码

合集下载

用VBA验证身份证号码的正确性

用VBA验证身份证号码的正确性

用VBA验证身份证号码的正确性
洪成波;张贻忠
【期刊名称】《电脑编程技巧与维护》
【年(卷),期】2012(000)023
【摘要】用Excel VBA编写一段程序,来验证身份证号码位数是否为18位(二代要求)、字符是否合法、号码是否正确,从而达到身份证号码自动验证,去掉打印核对环节,提高工作效率.
【总页数】5页(P25-28,38)
【作者】洪成波;张贻忠
【作者单位】
【正文语种】中文
【相关文献】
1.如何利用VisualBasic开发身份证号码批量验证工具软件 [J], 刘小龙
2.应用VBA提取身份证号码中的个人信息 [J], 马莉
3.身份证号码验证在审计中的应用与思考 [J], 高丽霞
4.Web开发中15位和18位身份证号码同时验证之探讨 [J], 李硕
5.一种比较器排序网络正确性验证方法 [J], 董卫;王婷婷
因版权原因,仅展示原文概要,查看原文内容请购买。

vb源代码crc32自校验(VB source code, crc32 self calibration)

vb源代码crc32自校验(VB source code, crc32 self calibration)

vb源代码-crc32自校验(VB source code, -crc32 selfcalibration)Class module (name clsCRC) codeOption ExplicitPublic Enum CRCAlgorithmsCRC16CRC32End EnumPrivate m_Algorithm As BooleanPrivate m_CRC16 As LongPrivate m_CRC16Asm () As BytePrivate m_CRC16Init As BooleanPrivate m_CRC16Table (0, To 255) As LongPrivate m_CRC32 As LongPrivate m_CRC32Asm () As BytePrivate m_CRC32Init As BooleanPrivate m_CRC32Table (0, To 255) As LongPrivate, Declare, Function, CallWindowProc, Lib, user32, Alias, CallWindowProcA, ByVal, As, Long, ByVal, hWnd, As, Long, ByVal, Msg, As, Long, ByVal, wParam, As, Long, ByVal, lParam, As, Long,, lpPrevWndFunc, As, LongPublic, Function, AddBytes (ByteArray ()) As Byte) As VariantDim ByteSize As LongOn, Local, Error, GoTo, NoDataByteSize = UBound (ByteArray) - LBound (ByteArray) + 1On Local Error GoTo 0Select Case m_AlgorithmCase CRC16Call, CallWindowProc (VarPtr (m_CRC16Asm (0)), VarPtr(m_CRC16), VarPtr (ByteArray (LBound (ByteArray))), VarPtr (m_CRC16Table (0)), ByteSize)Case CRC32Call, CallWindowProc (VarPtr (m_CRC32Asm (0)), VarPtr(m_CRC32), VarPtr (ByteArray (LBound (ByteArray))), VarPtr (m_CRC32Table (0)), ByteSize)End SelectNoData:AddBytes = ValueEnd FunctionPublic, Function, AddString (Text, As, String) As VariantAddString = AddBytes (StrConv (Text, vbFromUnicode))End FunctionPublic, Property, Let, Algorithm (New_Value, As, CRCAlgorithms)M_Algorithm = New_ValueSelect Case m_AlgorithmCase CRC16If (Not, m_CRC16Init), Then, Call, InitializeCRC16Case CRC32If (Not, m_CRC32Init), Then, Call, InitializeCRC32End SelectCall ClearEnd PropertyPublic, Property, Get, Algorithm (), As, CRCAlgorithmsAlgorithm = m_AlgorithmEnd PropertyPublic, Function, CalculateBytes (ByteArray ()) As Byte) As VariantCall ClearCalculateBytes = AddBytes (ByteArray)End FunctionPublic, Function, CalculateFile (Filename, As, String) As VariantDim Filenr As IntegerDim ByteArray () As ByteIf (FileLen (Filename) = 0) Then, Exit, FunctionFilenr = FreeFile二进制打开文件作为# filenrReDim ByteArray(0~LOF(filenr)- 9)得到# filenr,bytearray()近# filenrcalculatefile = calculatebytes(ByteArray)端功能公共财产得到value()变异选择案例m_algorithm案例CRC16价值=(m_crc16和65535)案例CRC32价值=(不m_crc32)最后选择最后的财产公共财产让价值(new_value变异)选择案例m_algorithm案例CRC16m_crc16 = new_value案例CRC32m_crc32 = new_value最后选择最后的财产私有子initializecrc16() 暗淡我一样长暗j长k长小CRC昏暗的SASM作为字符串对于我= 0比255k = i * 256CRC = 0对于j = 0到7如果((CRC异或k)和32768)= 32768)CRC(CRC×2)异或和h1021其他的CRC =(CRC * 2)最后如果k=k * 2下一个m_crc16table(我)= CRC下一个SASM=“5589e55756505351528b45088b008b750c8b7d108b4d1431db8a1e30 e3668b149f30c66689d0464975ef25ffff00008b4d0889015a595b585e5 f89ec5dc21000”ReDim m_crc16asm(0 Len(SASM)2 - 1)我= 1 Len(SASM)步骤2m_crc16asm(我2)=瓦迩(“H”和美元中期(SASM,I,2))下一个m_crc16init =真端子公共子clear()m_crc16 = 0m_crc32 =和hffffffff端子私有子initializecrc32()暗淡我一样长昏暗的SASM作为字符串m_crc32table(0)= & H0m_crc32table(1)=与h77073096 m_crc32table(2)=与hee0e612c m_crc32table(3)=与h990951ba m_crc32table(4)=与h76dc419 m_crc32table(5)=与h706af48fm_crc32table(6)=与he963a535 m_crc32table(7)=与h9e6495a3 m_crc32table(8)=与hedb8832 m_crc32table(9)=与h79dcb8a4 m_crc32table(10)=与he0d5e91e m_crc32table(11)=与h97d2d988 m_crc32table(12)=与h9b64c2b m_crc32table(13)=与h7eb17cbd m_crc32table(14)=与he7b82d07 m_crc32table(15)=与h90bf1d91 m_crc32table(16)=与h1db71064 m_crc32table(17)=与h6ab020f2 m_crc32table(18)=与hf3b97148 m_crc32table(19)=与h84be41de m_crc32table(20)=与h1adad47d m_crc32table(21)=与h6ddde4ebm_crc32table(22)=与hf4d4b551 m_crc32table(23)=与h83d385c7 m_crc32table(24)=与h136c9856 m_crc32table(25)=与h646ba8c0 m_crc32table(26)=与hfd62f97a m_crc32table(27)=与h8a65c9ec m_crc32table(28)=与h14015c4f m_crc32table(29)=与h63066cd9 m_crc32table(30)=与hfa0f3d63 m_crc32table(31)=与h8d080df5 m_crc32table(32)=与h3b6e20c8 m_crc32table(33)=与h4c69105e m_crc32table(34)=与hd56041e4 m_crc32table(35)=与ha2677172 m_crc32table(36)=与h3c03e4d1m_crc32table(37)=与h4b04d447 m_crc32table(38)=与hd20d85fd m_crc32table(39)=与ha50ab56b m_crc32table(40)=与h35b5a8fa m_crc32table(41)=与h42b2986c m_crc32table(42)=与hdbbbc9d6 m_crc32table(43)=与hacbcf940 m_crc32table(44)=与h32d86ce3 m_crc32table(45)=与h45df5c75 m_crc32table(46)=与hdcd60dcf m_crc32table(47)=与habd13d59 m_crc32table(48)=与h26d930ac m_crc32table(49)=与h51de003a m_crc32table(50)=与hc8d75180 m_crc32table(51)=与hbfd06116 m_crc32table(52)=与h21b4f4b5m_crc32table(53)=与h56b3c423 m_crc32table(54)=与hcfba9599 m_crc32table(55)=与hb8bda50f m_crc32table(56)=与h2802b89e m_crc32table(57)=与h5f058808 m_crc32table(58)=与hc60cd9b2 m_crc32table(59)=与hb10be924 m_crc32table(60)=与h2f6f7c87 m_crc32table(61)=与h58684c11 m_crc32table(62)=与hc1611dab m_crc32table(63)=与hb6662d3d m_crc32table(64)=与h76dc4190 m_crc32table(65)=与h1db7106 m_crc32table(66)=与h98d220bc m_crc32table(67)=与hefd5102am_crc32table(68)=与h71b18589 m_crc32table(69)=与h6b6b51f m_crc32table(70)=与h9fbfe4a5 m_crc32table(71)=与he8b8d433 m_crc32table(72)=与h7807c9a2 m_crc32table(73)=与hf00f934 m_crc32table(74)=与h9609a88e m_crc32table(75)=与he10e9818 m_crc32table(76)=与h7f6a0dbb m_crc32table(77)=与h86d3d2d m_crc32table(78)=与h91646c97 m_crc32table(79)=与he6635c01 m_crc32table(80)=与h6b6b51f4 m_crc32table(81)=与h1c6c6162 m_crc32table(82)=与h856530d8 m_crc32table(83)=与hf262004em_crc32table(84)=与h6c0695ed m_crc32table(85)=与h1b01a57b m_crc32table(86)=与h8208f4c1 m_crc32table(87)=与hf50fc457 m_crc32table(88)=与h65b0d9c6 m_crc32table(89)=与h12b7e950 m_crc32table(90)=与h8bbeb8ea m_crc32table(91)=与hfcb9887c m_crc32table(92)=与h62dd1ddf m_crc32table(93)=与h15da2d49 m_crc32table(94)=与h8cd37cf3 m_crc32table(95)=与hfbd44c65 m_crc32table(96)=与h4db26158 m_crc32table(97)=与h3ab551ce m_crc32table(98)=与ha3bc0074m_crc32table(99)=与hd4bb30e2 m_crc32table(100)=与h4adfa541 m_crc32table(101)=与h3dd895d7 m_crc32table(102)=与ha4d1c46d m_crc32table(103)=与hd3d6f4fb m_crc32table(104)=与h4369e96a m_crc32table(105)=与h346ed9fc m_crc32table(106)=与had678846 m_crc32table(107)=与hda60b8d0 m_crc32table(108)=与h44042d73 m_crc32table(109)=与h33031de5 m_crc32table(110)=与haa0a4c5f m_crc32table(111)=与hdd0d7cc9 m_crc32table(112)=与h5005713c m_crc32table(113)=与h270241aa m_crc32table(114)=与hbe0b1010m_crc32table(115)=与hc90c2086 m_crc32table(116)=与h5768b525 m_crc32table(117)=与h206f85b3 m_crc32table(118)=与hb966d409 m_crc32table(119)=与hce61e49f m_crc32table(120)=与h5edef90e m_crc32table(121)=与h29d9c998 m_crc32table(122)=与hb0d09822 m_crc32table(123)=与hc7d7a8b4 m_crc32table(124)=与h59b33d17 m_crc32table(125)=与h2eb40d81 m_crc32table(126)=与hb7bd5c3b m_crc32table(127)=与hc0ba6cad m_crc32table(128)=与hedb88320 m_crc32table(129)=与h9abfb3b6m_crc32table(130)=与h3b6e20c m_crc32table(131)=与h74b1d29a m_crc32table(132)=与head54739 m_crc32table(133)=与h9dd277af m_crc32table(134)=与h4db2615 m_crc32table(135)=与h73dc1683 m_crc32table(136)=与he3630b12 m_crc32table(137)=与h94643b84 m_crc32table(138)=与hd6d6a3e m_crc32table(139)=与h7a6a5aa8 m_crc32table(140)=与he40ecf0b m_crc32table(141)=与h9309ff9d m_crc32table(142)=与ha00ae27 m_crc32table(143)=与h7d079eb1 m_crc32table(144)=与hf00f9344 m_crc32table(145)=与h8708a3d2m_crc32table(146)=与h1e01f268 m_crc32table(147)=与h6906c2fe m_crc32table(148)=与hf762575d m_crc32table(149)=与h806567cb m_crc32table(150)=与h196c3671 m_crc32table(151)=与h6e6b06e7 m_crc32table(152)=与hfed41b76 m_crc32table(153)=与h89d32be0 m_crc32table(154)=与h10da7a5a m_crc32table(155)=与h67dd4acc m_crc32table(156)=与hf9b9df6f m_crc32table(157)=与h8ebeeff9 m_crc32table(158)=与h17b7be43 m_crc32table(159)=与h60b08ed5 m_crc32table(160)=与hd6d6a3e8m_crc32table(161)=与ha1d1937e m_crc32table(162)=与h38d8c2c4 m_crc32table(163)=与h4fdff252 m_crc32table(164)=与hd1bb67f1 m_crc32table(165)=与ha6bc5767 m_crc32table(166)=与h3fb506dd m_crc32table(167)=与h48b2364b m_crc32table(168)=与hd80d2bda m_crc32table(169)=与haf0a1b4c m_crc32table(170)=与h36034af6 m_crc32table(171)=与h41047a60 m_crc32table(172)=与hdf60efc3 m_crc32table(173)=与ha867df55 m_crc32table(174)=与h316e8eef m_crc32table(175)=与h4669be79 m_crc32table(176)=与hcb61b38cm_crc32table(177)=与hbc66831a m_crc32table(178)=与h256fd2a0 m_crc32table(179)=与h5268e236 m_crc32table(180)=与hcc0c7795 m_crc32table(181)=与hbb0b4703 m_crc32table(182)=与h220216b9 m_crc32table(183)=与h5505262f m_crc32table(184)=与hc5ba3bbe m_crc32table(185)=与hb2bd0b28 m_crc32table(186)=与h2bb45a92 m_crc32table(187)=与h5cb36a04 m_crc32table(188)=与hc2d7ffa7 m_crc32table(189)=与hb5d0cf31 m_crc32table(190)=与h2cd99e8b m_crc32table(191)=与h5bdeae1dm_crc32table(192)=与h9b64c2b0 m_crc32table(193)=与hec63f226 m_crc32table(194)=与h756aa39c m_crc32table(195)=与h26d930a m_crc32table(196)=与h9c0906a9 m_crc32table(197)=与heb0e363f m_crc32table(198)=与h72076785 m_crc32table(199)=与h5005713 m_crc32table(200)=与h95bf4a82 m_crc32table(201)=与he2b87a14 m_crc32table(202)=与h7bb12bae m_crc32table(203)=与hcb61b38 m_crc32table(204)=与h92d28e9b m_crc32table(205)=与he5d5be0d m_crc32table(206)=与h7cdcefb7 m_crc32table(207)=与hbdbdf21m_crc32table(208)=与h86d3d2d4 m_crc32table(209)=与hf1d4e242 m_crc32table(210)=与h68ddb3f8 m_crc32table(211)=与h1fda836e m_crc32table(212)=与h81be16cd m_crc32table(213)=与hf6b9265b m_crc32table(214)=与h6fb077e1 m_crc32table(215)=与h18b74777 m_crc32table(216)=与h88085ae6 m_crc32table(217)=与hff0f6a70 m_crc32table(218)=与h66063bca m_crc32table(219)=与h11010b5c m_crc32table(220)=与h8f659eff m_crc32table(221)=与hf862ae69 m_crc32table(222)=与h616bffd3m_crc32table(223)=与h166ccf45 m_crc32table(224)=与ha00ae278 m_crc32table(225)=与hd70dd2ee m_crc32table(226)=与h4e048354 m_crc32table(227)=与h3903b3c2 m_crc32table(228)=与ha7672661 m_crc32table(229)=与hd06016f7 m_crc32table(230)=与h4969474d m_crc32table(231)=与h3e6e77db m_crc32table(232)=与haed16a4a m_crc32table(233)=与hd9d65adc m_crc32table(234)=与h40df0b66 m_crc32table(235)=与h37d83bf0 m_crc32table(236)=与ha9bcae53 m_crc32table(237)=与hdebb9ec5 m_crc32table(238)=与h47b2cf7fm_crc32table(239)=与h30b5ffe9 m_crc32table(240)=与hbdbdf21c m_crc32table(241)=与hcabac28a m_crc32table(242)=与h53b39330 m_crc32table(243)=与h24b4a3a6 m_crc32table(244)=与hbad03605 m_crc32table(245)=与hcdd70693 m_crc32table(246)=与h54de5729 m_crc32table(247)=与h23d967bf m_crc32table(248)=与hb3667a2e m_crc32table(249)=与hc4614ab8 m_crc32table(250)=与h5d681b02 m_crc32table(251)=与h2a6f2b94 m_crc32table(252)=与hb40bbe37 m_crc32table(253)=与hc30c8ea1m_crc32table(254)=与h5a05df1bm_crc32table(255)=与h2d02ef8dSASM=“5589e557565053518b45088b008b750c8b7d108b4d1431db8a1e30c3 c1e80833049f464975f28b4d088901595b585e5f89ec5dc21000”ReDim m_crc32asm(0 Len(SASM)2 - 1)我= 1 Len(SASM)步骤2m_crc32asm(我2)=瓦迩(“H”和美元中期(SASM,I,2))下一个m_crc32init =真端子私有子class_initialize()CRC32算法=端子“窗口代码私有函数getcrc32()作为字符串昏暗的绿景为字符串错误crcerror绿景=应用程序路径和“\”和app.exename“.exe”昏暗的CCRC作为新的clscrc,filecrc美元CRC32算法= CCRC。

身份证校验VBA宏

身份证校验VBA宏

身份证校验VBA宏Function IDCheck(e)IDCheck = TruearrVerifyCode = 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 = FalseExit FunctionEnd IfDim Ai'取身份证前17位If Len(e) = 18 ThenAi = Mid(e, 1, 17)ElseIf Len(e) = 15 ThenAi = eAi = Left(Ai, 6) & "19" & Mid(Ai, 7, 9) '转换成17位End IfIf Not IsNumeric(Ai) Then'IDCheck= "身份证除最后一位外,必须为数字!"IDCheck = FalseExit FunctionEnd IfDim strYear, strMonth, strDaystrYear = 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) ThenIf DateDiff("yyyy", Now, BirthDay) < -140 Or CDate(BirthDay) > Date Then'IDCheck= "身份证输入错误!"IDCheck = FalseExit FunctionEnd IfIf strMonth > 12 Or strDay > 31 ThenIDCheck = False'IDCheck= "身份证输入错误!"Exit FunctionEnd IfElse'IDCheck= "身份证输入错误!"IDCheck = FalseExit FunctionEnd IfDim i, TotalmulAiWi'十七位数字本体码加权求和For i = 0 To 16TotalmulAiWi = TotalmulAiWi + CInt(Mid(Ai, i + 1, 1)) * Wi(i) NextDim modValuemodValue = TotalmulAiWi Mod 11 '计算模Dim strVerifyCodestrVerifyCode = arrVerifyCode(modValue) '通过模得到对应的校验码Ai = Ai & strVerifyCodeIDCheck = AiIf Len(e) = 18 And e <> Ai Then'IDCheck= "身份证号码输入错误!"IDCheck = "False" & AiExit FunctionEnd IfEnd Function。

请教狐狸爸爸:身份证号码有效性验证,提取籍贯、性别、出生日期、年龄信息(VBA代码)

请教狐狸爸爸:身份证号码有效性验证,提取籍贯、性别、出生日期、年龄信息(VBA代码)

请教狐狸爸爸:身份证号码有效性验证,提取籍贯、性别、出生日期、年龄信息(VBA代码)Option Explicit'====================================== ============================='函数名称: IsIDNumber'功能描述:根据GB11643-1999编码规则验证18位身份证号码是否有效'输入参数:参数1:IDNumber 必需的,18位身份证号码'返回参数:有效返回True,无效返回False'兼容性:'使用示例:IsIDNumber(*******************")'返回True '相关调用:'作者:红尘如烟'创建日期: 20010-4-25'====================================== =============================Function IsIDNumber(ByVal IDNumber As String) As Boolean Const W As String = "79058421637905842" '加权因子Const C As String = "10X98765432" '校验码Dim S As Integer, i As Integer, T As IntegerIDNumber = UCase(Trim(IDNumber))If Len(IDNumber) <> 18 Then Exit FunctionIf Not IsNumeric(Mid(IDNumber, 1, 17)) Then Exit Function If Not IDNumber Like "*[0-9X]" Then Exit FunctionFor i = 1 To 17T = Mid(W, i, 1)If T = 0 Then T = 10S = S + Mid(IDNumber, i, 1) * TNextT = S Mod 11If Right(IDNumber, 1) = Mid(C, T + 1, 1) Then IsIDNumber = TrueEnd FunctionPrivate Sub Form_Load()End SubPrivate Sub txtAge_BeforeUpdate(Cancel As Integer)End SubPrivate Sub txtIDNumber_AfterUpdate()If Nz(Me.txtIDNumber) = "" Then Exit Sub'验证输入的是否为一个有效的身份证号码If Not IsIDNumber(Nz(Me.txtIDNumber)) ThenMsgBox "无效的身份证号码!", vbInformationMe.txtIDNumber = NullMe.txtBirthday = NullMe.txtSex = NullMe.txtNativePlace = NullElse'从表中取得籍贯Me.txtNativePlace = DLookup("[FAddress]", "tblNativePlaceList", "[FNumber]=" & Left(Me.txtIDNumber, 6)) '提取出生日期(第7-14位)Me.txtBirthday = DateSerial(Mid(Me.txtIDNumber, 7, 4), Mid(Me.txtIDNumber, 11, 2), Mid(Me.txtIDNumber, 13, 2)) '提取性别(第17位,奇数为男,偶数为女)Me.txtSex = IIf(Mid(Me.txtIDNumber, 17, 1) Mod 2 = 0, "女", "男")'根据出生日期计算年龄,精确到年' Me.txtAge = DateDiff("yyyy", Me.txtBirthday, Date)'根据出生日期计算年龄,精确到月Me.txtAge = DateDiff("m", Me.txtBirthday, Date) \ 12'根据出生日期计算年龄,精确到天' Me.txtAge = DateDiff("d", Me.txtBirthday, Date) \ 365.25End IfEnd Sub。

JavaScript验证18位身份证号码最后一位正确性的实现代码

JavaScript验证18位身份证号码最后一位正确性的实现代码

JavaScript验证18位⾝份证号码最后⼀位正确性的实现代码根据⾝份证号码推算出最后⼀位的正确性,如果不正确还会给出正确结果,⾮常有意思的⼀断程序。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>javascript 18位⾝份证号码最后⼀位校验码</title></head><body><script>function getIDChar18(id) {var arr = id.split(''), sum = 0, vc = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];for (var i = 0; i < 17; i++) sum += vc[i] * parseInt(arr[i]);return ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'][sum % 11];}function ValidID(id) {if (/^\d{18}$/.test(id)) {var c = id.charAt(17), rc = getIDChar18(id);if (c == rc) showRst('您输⼊的18位⾝份证号码正确!<br>⽣⽇:' + id.substr(6, 8) + '<br>性别:' + ['⼥', '男'][parseInt(id.charAt(16)) % 2]);else showRst('您输⼊的18位⾝份证号码检验码错误,18位校验码应该为' + rc + '!');}else showRst('请输⼊18位数字的⾝份证号码!');}function showRst(msg) {document.getElementById('rst').innerHTML=msg }</script><input type="text" onblur="ValidID(this.value)" /><div id="rst"></div></body></html>。

用VBA构建身份证验证函数

用VBA构建身份证验证函数

用VBA构建身份证验证函数同学们在用VBA构建用户管理系统时,需要收集用户信息,在采集用户信息时,经常会遇到身份证信息输入混乱的情况,有的用户胡乱输入、有的输入明显错误,如何对身份证信息进行校验,规范输入信息呢?本节深入探讨用VBA代码进行身份证校验。

身份证号码的编码规则身份证号码共18位,由17位本体码和1位校验码组成。

1.前6位是地址码,表示登记户口时所在地的行政区划代码,依照《中华人民共和国行政区划代码》国家标准(GB/T2260)的规定执行;2.7到14位是出生年月日,采用YYYYMMDD格式;3.15到17位是顺序码,表示在同一地址码所标识的区域范围内,对同年、同月、同日出生的人编订的顺序号,顺序码的奇数分配给男性,偶数分配给女性,即第17位奇数表示男性,偶数表示女性;4.第18位是校验码,采用ISO 7064:1983, MOD 11-2校验字符系统。

一代身份证与二代身份证的区别在于:1.一代身份证是15位,二代身份证是18位;2.一代身份证出生年月日采用YYMMDD格式,二代身份证出生年月日采用YYYYMMDD格式;3.一代身份证无校验码,二代身份证有校验码。

1.区划代码校验首先,把从网上下载的行政区划代码放入名为“区划代码”的工作表中,此步骤主要是校验用户输入的前6位是否在区划代码中找到。

代码如下:arr = Worksheets("区划代码").Range("a1", Worksheets("区划代码").Range("a" & Rows.Count).End(xlUp))AreaCode = Mid(MyId, 1, 6) '提取身份证前6位IsCorrect = FalseFor i = 1 To UBound(arr)If CStr(arr(i, 1)) = AreaCode ThenIsCorrect = TrueExit ForEnd IfNextIf IsCorrect = False ThenIdCardCheck = "区划代码错误"Exit FunctionEnd If2.身份证的长度验证身份证字符长度应为18位或15位,其他长度的不符合要求If Not (Len(MyId) = 18 Or Len(MyId) = 15) ThenIdCardCheck = "身份信息位数不符合要求"Exit FunctionEnd If3.验证日期字符串是否合法(1)验证身份证信息中除最后一位是否含有字符,如果含有字符,说明不合法;(2)验证日期格式是否合法。

VB编程份证校验尾号方法

VB编程份证校验尾号方法
VersionCompanyName="美好的家"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
Caption = " 生成新的证号"
Height = 255
Left = 360
TabIndex = 2
Top = 480
Width = 1815
End
Begin VB.OptionButton Option1
Caption = " 校验是否正确"
Height = 255
End
Begin boBox Combo6
Height = 300
Left = 3480
TabIndex ቤተ መጻሕፍቲ ባይዱ = 9
Text = "Combo6"
Height = 495
Left = 240
MaxLength = 18
TabIndex = 3
Text = "添入17位验证码或完整号码"
Top = 360
Visible = 0 'False
Width = 2415
End
Begin mandButton Command1
Caption = "Command1"
Left = 360
TabIndex = 1

二代身份证读卡器二次开发代码

二代身份证读卡器二次开发代码
<input size=25 name=fnation maxLength=25 > </P></td> </tr> <tr> <td class="color2" > <P align=center><FONT size=3>出生:</FONT></P></td> <td class="color2" > <P align=left>
Public Function FTPTxtFile(site, file) 'ftp 上传 Inet1.URL = "ftp://" & site Inet1.Protocol = icFTP erName = "upphoto" ‘ftp 用户(可改) Inet1.Password = "upphoto" ‘ftp 密码(可改) Inet1.Execute , "PUT c:/aha.bmp " & file ‘上传 c 盘根目录的 aha.bmp 文件 Do While Inet1.StillExecuting
3.测试代码(保存为 test.htm 就可以了) 测试时会提示安装 cab 包(把 cab 包与 test.htm 放在同一个文件夹内)。 <HTML> <HEAD> <TITLE>htmok.CAB</TITLE> </HEAD> <BODY> <!--网页调用--> <!-调用插件--> <OBJECT

身份证号码有效性校验程序delphi源代码

身份证号码有效性校验程序delphi源代码

身份证号码有效性校验程序delphi源代码unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls, ComCtrls;typeTForm1 = class(TForm)Edit1: TEdit;Button1: TButton;Label1: TLabel;procedure Button1Click(Sender: TObject);private{ Private declarations }public{ Public declarations }end;varForm1: TForm1;implementation{$R *.dfm}function GetVerifyBit(sIdentityNum: string): Char; //取得最后一位校验码:公式varnNum: Integer;beginResult := #0; //求总nNum := StrToInt(sIdentityNum[1]) * 7 +StrToInt(sIdentityNum[2]) * 9 +StrToInt(sIdentityNum[3]) * 10 +StrToInt(sIdentityNum[4]) * 5 +StrToInt(sIdentityNum[5]) * 8 +StrToInt(sIdentityNum[6]) * 4 +StrToInt(sIdentityNum[7]) * 2 +StrToInt(sIdentityNum[8]) * 1 +StrToInt(sIdentityNum[9]) * 6 +StrToInt(sIdentityNum[10]) * 3 +StrToInt(sIdentityNum[11]) * 7 +StrToInt(sIdentityNum[12]) * 9 +StrToInt(sIdentityNum[13]) * 10 +StrToInt(sIdentityNum[14]) * 5 +StrToInt(sIdentityNum[15]) * 8 +StrToInt(sIdentityNum[16]) * 4 +StrToInt(sIdentityNum[17]) * 2;nNum := nNum mod 11; //除11取余case nNum of //对应的校验码0: Result := '1';1: Result := '0';2: Result := 'X';3: Result := '9';4: Result := '8';5: Result := '7';6: Result := '6';7: Result := '5';8: Result := '4';9: Result := '3';10: Result := '2';end;end;function ValidatePID(const APID: string): string; varL: Integer;sCentury: string;sYear2Bit: string;sMonth: string;sDate: string;sSex: string;iSex: Integer;iCentury: Integer;iMonth: Integer;iDate: Integer;CRCFact: string; //18位证号的实际值CRCTh: string; //18位证号的理论值FebDayAmt: Byte; //2月天数beginL := Length(APID); //校验长度if (L in [15, 18]) = False thenbeginResult := Format('身份证号不是15位或18位(实际位数:%1:d)', [APID, L]);Exit;end;CRCFact := '';if L = 18 thenbeginsCentury := Copy(APID, 7, 2);iCentury := StrToInt(sCentury);if (iCentury in [18..20]) = False thenbeginResult := Format('身份证号码无效:18位证号的年份前两位(当前为:%0:S)不在18-20之间', [sCentury]);Exit;end;sYear2Bit := Copy(APID, 9, 2);sMonth := Copy(APID, 11, 2);sDate := Copy(APID, 13, 2);CRCFact := Copy(APID, 18, 1);iSex := StrToInt(Copy(APID, 17, 1));endelsebeginsCentury := '19';sYear2Bit := Copy(APID, 7, 2);sMonth := Copy(APID, 9, 2);sDate := Copy(APID, 11, 2);iSex := StrToInt(Copy(APID, 15, 1));end;iMonth := StrToInt(sMonth);iDate := StrToInt(sDate);if (iMonth in [01..12]) = False thenbeginResult := Format('身份证号码无效:月份(%0:s)无效!不在“01-12”之间!', [sMonth]);Exit;end;if (iMonth in [1, 3, 5, 7, 8, 10, 12]) thenbeginif (iDate in [01..31]) = False thenbeginResult := Format('身份证号码无效:日期(%0:s)无效!不在“1-31”之间!', [sDate]);Exit;end;end;if (iMonth in [4, 6, 9, 11]) thenbeginif (iDate in [01..30]) = False thenbeginResult := Format('身份证号码无效:日期(%0:s)无效!不在“1-30”之间!', [sDate]);Exit;end;end;//闰年if IsLeapYear(StrToInt(sCentury + sYear2Bit)) = True thenbeginFebDayAmt := 29;endelsebeginFebDayAmt := 28;end;if (iMonth in [2]) thenbeginif (iDate in [01..FebDayAmt]) = False thenbeginResult := Format('身份证号码无效:日期(%0:s)无效!不在“1-'+inttostr(FebDayAmt)+'”之间!', [sDate]);Exit;end;end;if iSex mod 2 = 0 thenbeginsSex := '女';endelsebeginsSex := '男';end;if CRCFact <> '' thenbeginCRCTh := GetVerifyBit(APID);if CRCFact <> CRCTh thenbeginResult := Format('身份证号码无效!请按以下步骤进行检查:'#13'1、最后一位要改成:“' + CRCTh + '”吗?(现在是:'+CRCFact+')'#13'2、出生日期是“' + sCentury + sYear2Bit + '年' + inttostr(iMonth) + '月' +inttostr(iDate) + '日”(' +sCentury + sYear2Bit +sMonth+sDate+ ')对吗?'#13'3、性别为“' + sSex + '”(倒数第2位是:' + inttostr(iSex) + ')对吗?'#13'4、前6位地区码为:' + Copy(APID, 1, 6) + ',对吗?'#13'5、倒数第4、3位('+Copy(APID, L-3, 2)+')是否正确?', [APID]);Exit;end;Result := '身份证号正确('+inttostr(L)+'位,带校验码)!出生日期:' + sCentury + sYear2Bit + '年' + inttostr(iMonth) + '月' + inttostr(iDate) + '日,性别:' + sSex;endelsebeginResult := '身份证号正确('+inttostr(L)+'位,无校验码)!出生日期:' + sCentury + sYear2Bit + '年' + inttostr(iMonth) + '月' + inttostr(iDate) + '日,性别:' + sSex;end;end;procedure TForm1.Button1Click(Sender: TObject);beginMessageBox(GetActiveWindow(), pchar(ValidatePID(Edit1.Text)), '提示信息!',mb_iconwarning);end;end.。

vba 判断excel本列身份证号是否正确

vba 判断excel本列身份证号是否正确

Function getYjm(num)'dd = "新身份证:" & Left(xian, 6) & "19" & Right(xian, 9) & CStr(getYjm(xian)) Dim ciDIf Len(num) = 15 ThenciD = Left(num, 6) & "19" & Right(num, 9)ElseIf Len(num) = 17 Or Len(num) = 18 ThenciD = Left(num, 17)ElsegetYjm = "f"Exit FunctionEnd IfEnd IfFor i = 1 To Len(ciD)If Not IsNumeric(Mid(ciD, i, 1)) ThengetYjm = "f"Exit FunctionEnd IfNext insum = Mid(ciD, 1, 1) * 7nsum = nsum + Mid(ciD, 2, 1) * 9nsum = nsum + Mid(ciD, 3, 1) * 10nsum = nsum + Mid(ciD, 4, 1) * 5nsum = nsum + Mid(ciD, 5, 1) * 8nsum = nsum + Mid(ciD, 6, 1) * 4nsum = nsum + Mid(ciD, 7, 1) * 2nsum = nsum + Mid(ciD, 8, 1) * 1nsum = nsum + Mid(ciD, 9, 1) * 6nsum = nsum + Mid(ciD, 10, 1) * 3nsum = nsum + Mid(ciD, 11, 1) * 7nsum = nsum + Mid(ciD, 12, 1) * 9nsum = nsum + Mid(ciD, 13, 1) * 10nsum = nsum + Mid(ciD, 14, 1) * 5nsum = nsum + Mid(ciD, 15, 1) * 8nsum = nsum + Mid(ciD, 16, 1) * 4nsum = nsum + Mid(ciD, 17, 1) * 2'*计算校验位check_number = 12 - nsum Mod 11If check_number = 10 Thencheck_number = "X"End IfIf check_number = 12 Thencheck_number = "1"End IfIf check_number = 11 Thencheck_number = "0"End IfgetYjm = check_numberEnd FunctionFunction getCsrc(num, flaG)lenx = Len(num)If lenx = 15 Thenyy = "19" & Mid(xian, 7, 2)mm = Mid(num, 9, 2)dd = Mid(num, 11, 2)End IfIf lenx = 18 Thenyy = Mid(num, 7, 4)mm = Mid(num, 11, 2)dd = Mid(num, 13, 2)End Ifss = yy & "/" & mm & "/" & ddIf flaG = 0 ThenIf IsDate(ss) ThengetCsrc = ssElsegetCsrc = "1900/02/02"End IfElseIf IsDate(ss) ThengetCsrc = ssElsegetCsrc = "f"End IfEnd IfEnd FunctionFunction getSbie(num, flaG)Dim yy, mm, dd As Stringlenx = Len(num)If lenx = 15 Thenaa = Mid(num, 15, 1) '15位身分证取第十五位,能被2整除为女性End IfIf lenx = 18 Thenaa = Mid(num, 17, 1) '18位身分证取第十七位,能被2整除为女性End IfIf flaG = 0 ThenIf (Not IsNumeric(aa)) Or aa = "" Thenaa = 1End IfIf aa Mod 2 = 0 Thenxb = "女"Elsexb = "男"End IfgetSbie = xbElseIf (Not IsNumeric(aa)) Or aa = "" ThengetSbie = "f"Exit FunctionEnd IfIf aa Mod 2 = 0 Thenxb = "女"Elsexb = "男"End IfgetSbie = xbEnd IfEnd FunctionFunction banduanShengfen(num) As Boolean Dim a, b, c, da = getYjm(num)b = getCsrc(num, 1)c = getSbie(num, 1)num = Replace(num, "x", "X")d = Right(num, 1)If Len(num) = 18 ThenIf StrComp(d, a) = 0 ThenElsea = "f"End IfEnd IfIf (Len(num) < 15) Or (Len(num) > 18) Thena = "f"End IfIf 15 < Len(num) And Len(num) < 18 Thena = "f"End IfIf a = "f" Or b = "f" Or c = "f" Then banduanShengfen = FalseElsebanduanShengfen = TrueEnd IfEnd FunctionSub yianzhengShengfen()Dim rng As RangeDim selCount, i, j, k, concelCount, conrowCount As IntegerDim selStr(100) As StringDim selTemp() As StringDim Tempstr As StringconcelCount = edRange.Columns.CountconrowCount = edRange.Rows.CountFor Each rng In SelectionDoEventsselTemp = Split(rng.Address, "$")Tempstr = selTemp(1)j = 0For i = 0 To selCountIf selTemp(1) = selStr(i) Thenj = 1End IfNext iIf j = 0 ThenselStr(selCount) = selTemp(1)selCount = selCount + 1End IfNextk = 0Tempstr = ""For j = 1 To conrowCountDoEventsIf Not banduanShengfen(Replace(Range(selStr(0) & j).V alue, " ", "")) ThenRange(selStr(0) & j).Interior.Color = RGB(255, 98, 98)Tempstr = Tempstr & j & ","k = k + 1End IfNext jIf Not Range(selStr(0) & "1").Comment Is Nothing ThenRange(selStr(0) & "1").ClearCommentsIf k > 0 ThenRange(selStr(0) & "1").AddComment "本列中共" & k & "个身份号不对,其中:" & Left(Tempstr, Len(Tempstr) - 1) & "行身份证号不对"ElseRange(selStr(0) & "1").AddComment "本列身份证号全对"End IfElseIf k > 0 ThenRange(selStr(0) & "1").AddComment "本列中共" & k & "个身份号不对,其中:" & Left(Tempstr, Len(Tempstr) - 1) & "行身份证号不对"ElseRange(selStr(0) & "1").AddComment "本列身份证号全对"End IfEnd IfEnd Sub。

用excel做VBA身份证号码校队

用excel做VBA身份证号码校队
5.2 各模块中的代码
(1) 模块 1—启动验证程序 (插入模块编写): Sub auto_open()
Application.ScreenUpdating = False ' 关闭屏显 On Error Resume Next Dim i As Integer Dim HelpMenu As CommandBarControl Dim NewMenu As CommandBarPopup Dim MenuItem As CommandBarControl Dim SubMenuItem As CommandBarButton ' 隐藏常规菜单项 For i = 1 To mandBars(1).Controls.Count
DOI:10.16184/prg.2012.23.007
PROGRAM LANGUAGE
编程语言
用 VBA 验证身份证号码的正确性
洪成波 张贻忠
摘 要: 用 Excel VBA 编写一段程序, 来验证身份证号码位数是否为 18 位 (二代要求)、 字符是 否合法、 号码是否正确, 从而达到身份证号码自动验证, 去掉打印核对环节, 提高工作效率。 关键词: 身份证号码; Excel VBA; 正确性。
With MenuItem .Caption = "验证号码的正确性" .ShortcutText = "Ctrl+Shift+L" ' 添加快捷键 .FaceId = 25 .OnAction = "验号码正确性"
End With ' 利用 ID 属性查找帮助菜单
26 2012. 23
Байду номын сангаас
PROGRAM LANGUAGE

excel的身份证效验程序

excel的身份证效验程序

打开EXCEL,把宏的安全级别设置为“低”,以后再改回来。

然后打开VB编辑器,新建一模块,加入以下代码Function 身份证(n As Object)wi = Array("7", "9", "10", "5", "8", "4", "2", "1", "6", "3", "7", "9", "10", "5", "8", "4", "2") y = Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2")d = Array("29", "31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31", "30") s = EmptyIf Len(n) = 15 Then身份证 = "请填18位身份证号"Exit FunctionElseIf Len(n) = Empty Then身份证 = EemptyExit FunctionEnd If年份 = Val(Mid(n, 7, 4))月份 = Val(Mid(n, 11, 2))月份2 = 月份If 月份2 = 2 Thentt = Val(Mid(年份, 3, 2))If tt <> 0 Thentt = 年份 Mod 4If tt = 0 Then 月份2 = 0Elsett = 年份 Mod 400If tt = 0 Then 月份2 = 0End IfEnd If日期 = Val(Mid(n, 13, 2))If 日期 > Val(d(月份2)) Or 日期 = 0 Then身份证 = "日历无此日"Exit FunctionEnd IfIf 月份 > 12 Or 月份 = 0 Then身份证 = "日历无此月份"Exit FunctionEnd IfIf 年份 > Year(Date) Then身份证 = "还没生出来"Exit FunctionElseIf 年份 < Year(Date) - 100 Then身份证 = "百岁老人"Exit FunctionEnd IfIf Len(n) = 17 ThenFor h = 0 To 16r = Mid(n, h + 1, 1)s = s + r * wi(h)Next ht = s Mod 11身份证 = "校验码未填 " & y(t)ElseIf Len(n) = 18 ThenFor h = 0 To 16r = Mid(n, h + 1, 1)s = s + r * wi(h)Next ht = s Mod 11t = y(t)r = Mid(n, 18, 1)If t <> r Then身份证 = "False"Elsett = Val(Mid(n, 15, 3)) Mod 2If tt = 0 Then身份证 = "女"Else身份证 = "男"End IfEnd IfElseMsgBox "身份证位数不正确"End IfEnd Function然后返回EXCLE,把身份证号填入单格,再填入公式如:=身份证(A3。

vb居民身份证 校验函数

vb居民身份证 校验函数
CheckCIDC15 = "号码输入有误!月份和日期不匹配"
Exit Function
ElseIf Val(Mid(StrID15, 9, 2)) = 2 And (Val(Mid(StrID15, 11, 2)) = 30 Or Val(Mid(StrID15, 11, 2)) = 31) Then
Exit Function
Else
If (Val(Mid(StrID15, 9, 2)) = 4 Or Val(Mid(StrID15, 9, 2)) = 6 Or Val(Mid(StrID15, 9, 2)) = 9 Or Val(Mid(StrID15, 9, 2)) = 11) And Val(Mid(StrID15, 11, 2)) = 31 Then
Dim StrID17 As String, AiWi As Integer, Num As Integer, A18 As String
Dim sA, sDate
Dim iA
sA = Mid(StrID18, 7, 4)
sDate = sA & "-" & Mid(StrID18, 11, 2) & "-" & Mid(StrID18, 13, 2)
Case 1
StrID18 = StrID17 & "0"
Case 2
ቤተ መጻሕፍቲ ባይዱ StrID18 = StrID17 & "X"
Case 3
StrID18 = StrID17 & "9"
Case 4
Case 8

VB制作系统登录界面,包括用户名,密码和错误校验及效果全代码

VB制作系统登录界面,包括用户名,密码和错误校验及效果全代码

VB制作系统登录界面,包括用户名,密码和错误校验及效果全代码VB制作系统登录界面,包括用户名,密码和错误校验及效果全代码第十讲:教你用VB制作系统登录界面,包括用户名,密码和错误校验及效果全代码以下代码均为个人学习心得,经过测试并且无误,可以嵌入大型程序中作为身份认证的功能作用。

其中有一些窗体名和效果代码,不必复制,否则会出现错误,请仔细阅读核心代码理解即可。

红色代码部份为实现用户检测的关键代码,必需要有后台数据库用来存放用户信息,通过conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\HISDB.mdb"来连接,然后用If rs.EOF = True Then进行判断表中是否存在用户信息即可。

Option ExplicitDim Cnum As IntegerPrivate Sub CmdCancel_Click()'//结束EndEnd SubPrivate Sub CmdLogin_Click()Dim UserName As StringDim PassWord As StringDim conn As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim StrSQL As Stringconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &App.Path & "\HISDB.mdb"UserName = Trim(TxtUserName.T ext) '//将文本框内的值赋给定义好的全局变量PassWord = Trim(TxtPassword.Text) If UserName = "" Or PassWord = "" ThenMsgBox "对不起,用户或密码不能为空~请重新输入~~", vbCritical, "错误"ElseIf UserName <> Empty And PassWord <> Empty Then '//用户名与密码是否为空Cnum = Cnum + 1StrSQL = "select * from 用户信息表where 用户名称= '" & UserName & "'and 用户口令 ='" & PassWord & "'"rs.Open StrSQL, conn, adOpenKeyset, adLockPessimistic '//打开记录集If rs.EOF = True ThenMsgBox "对不起,无此用户或者密码不正确~请重新输入~~", vbCritical, "错误"TxtUserName.T ext = ""TxtPassword.Text = ""TxtUserName.SetFocusrs.CloseIf Cnum >= 3 ThenMsgBox "对不起,您已经多次失败,无权操作本系统~", vbCritical, "无权限"Unload MeExit SubEnd IfElse '登陆成功,以下为权限验证If rs.Fields("用户权限").Value = "系统管理" Then Frmmdimain.Show Unload MeElseIf rs.Fields("用户权限").Value = "挂号" ThenFrmregistration2.ShowUnload MeElseIf rs.Fields("用户权限").Value = "诊断" Then Frmdiagnose2.Show Unload MeElseIf rs.Fields("用户权限").Value = "收费" Then Frmcharges2.Show Unload MeElseIf rs.Fields("用户权限").Value = "发药" Then Frmmedicine2.Show Unload MeEnd Ifrs.CloseEnd IfEnd IfEnd SubPrivate Sub Form_Load()'//加载主窗时给文本框赋值TxtUserName.T ext = "Admin"TxtPassword.Text = "123"Cnum = 0End SubPrivate Sub TmrChangeColor_Timer() '//调用定义好的改变颜色过程, Call changecolor(LblWelcome(0), 0, 1, 2, 3, 4, 5, 6, 7) End SubPrivate Sub TmrMoveText1_Timer() '//移动LblShaSiLblShaSi(0).Move LblShaSi(0).Left + 20 LblShaSi(1).Move LblShaSi(1).Left + 20 End SubPrivate Sub TmrMoveText2_Timer() '//移动LblShaSiIf LblShaSi(0).Left + LblShaSi(0).Width >= Me.Width +LblShaSi(0).WidthThenLblShaSi(0).Move -1500End IfIf LblShaSi(1).Left + LblShaSi(1).Width >= Me.Width +LblShaSi(1).WidthThenLblShaSi(1).Move -1500End IfEnd Sub'//定义一个改变颜色的过程,下面的control就是我们所说的控件Sub changecolor(LCnt As Control, color1 As Integer, _ color2 As Integer, color3 As Integer, _color4 As Integer, color5 As Integer, _color6 As Integer, color7 As Integer, _color8 As Integer)Dim tmep As Integertmep = Val(LCnt.T ag) '//将返回包含于字符串内的数字赋给TEMP Select Case tmepCase color1LCnt.Tag = color2Case color2LCnt.Tag = color3Case color3LCnt.Tag = color4Case color4LCnt.Tag = color5Case color5LCnt.Tag = color6Case color6LCnt.Tag = color7Case color7LCnt.Tag = color8Case color8LCnt.Tag = color1End SelectLCnt.ForeColor = QBColor(LCnt.Tag) '//给控件LCnt中的字体赋予颜色,注意QBColor是将一值'//转换为三色,MSDN详解,我也是在那查的````哈End Sub。

如何利用Visual Basic开发身份证号码批量验证工具软件

如何利用Visual Basic开发身份证号码批量验证工具软件

s f z j y m= " X ”
Ca s e 3


f z j y m= … 9 ’
份证号码编码规则编写 了《 身份证号码批量验证工具》 软件 , 使身
份证号码核对工作变得简单 轻松 。

Ca s e4
s f z j y m = … 8 ’
Ca s e 5
( 3 ) 验证代码。
Pr iv a t e Su b y zC l i c k 0
_
n I = V a l ( M i d ¥ ( n u m, 1 , l 7 n 2 = V a l ( M i d ¥ ( n u m, 2 , l 9 n 3 = V a l ( M i d ¥ ( n u m, 3 , 1 ) 1 0
a d r ¥ = Mi d ¥ ( d k d h k . I n i t D i r &“ 、 ” &d k d h k . F i l e N a me 。 2 ,L e n ( d k d h k . I n i t Di r &“ \ ' ’ &d k d h k . F i l e N a me ) 一l 1
S e t a p p=Ne w Ex c e 1 . Ap p l i c a t i o n
n l 1 = V a l ( Mi d ¥ ( h u m, 1 1 , 1 ” 7
n l 2 = V a l ( Mi d ¥ ( n u m, 1 2 , l 9 n 1 3 = V a l ( Mi d ¥ ( n u m, 1 3 , 1 ) 1 0 n l 4 = Va l ( Mi d ¥ ( n u m, 1 4 , 1 ) ) 5 n l 5 = V a l ( Mi d ¥ ( n u m, 1 5 , l 8

基于javascript简单实现对身份证校验

基于javascript简单实现对身份证校验

基于javascript简单实现对⾝份证校验本⽂实例介绍了javascript简单实现对⾝份证的校验的关键性代码,分享给⼤家供⼤家参考,具体内容如下var vcity={ 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:"澳门",91:"国外"};checkCard = function(card){//是否为空if(card === ''){return "请输⼊⾝份证号,⾝份证号不能为空";}//校验长度,类型if(isCardNo(card) === false){return "您输⼊的⾝份证号码不正确,请重新输⼊";}//检查省份if(checkProvince(card) === false){return "您输⼊的⾝份证号码不正确,请重新输⼊";}//校验⽣⽇if(checkBirthday(card) === false){return "您输⼊的⾝份证号码⽣⽇不正确,请重新输⼊";}//检验位的检测if(checkParity(card) === false){return "您的⾝份证校验位不正确,请重新输⼊";}return "ok";};//检查号码是否符合规范,包括长度,类型isCardNo = function(card){//⾝份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后⼀位是校验位,可能为数字或字符Xvar reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/;if(reg.test(card) === false){return false;}return true;};//取⾝份证前两位,校验省份checkProvince = function(card){var province = card.substr(0,2);if(vcity[province] == undefined){return false;}return true;};//检查⽣⽇是否正确checkBirthday = function(card){var len = card.length;//⾝份证15位时,次序为省(3位)市(3位)年(2位)⽉(2位)⽇(2位)校验位(3位),皆为数字if(len == '15'){var re_fifteen = /^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/;var arr_data = card.match(re_fifteen);var year = arr_data[2];var month = arr_data[3];var day = arr_data[4];var birthday = new Date('19'+year+'/'+month+'/'+day);return verifyBirthday('19'+year,month,day,birthday);}//⾝份证18位时,次序为省(3位)市(3位)年(4位)⽉(2位)⽇(2位)校验位(4位),校验位末尾可能为X if(len == '18'){var re_eighteen = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/;var arr_data = card.match(re_eighteen);var year = arr_data[2];var month = arr_data[3];var day = arr_data[4];var birthday = new Date(year+'/'+month+'/'+day);return verifyBirthday(year,month,day,birthday);}return false;};//校验⽇期verifyBirthday = function(year,month,day,birthday){var now = new Date();var now_year = now.getFullYear();//年⽉⽇是否合理if(birthday.getFullYear() == year && (birthday.getMonth() + 1) == month && birthday.getDate() == day){//判断年份的范围(3岁到100岁之间)var time = now_year - year;if(time >= 3 && time <= 100){return true;}return false;}return false;};//校验位的检测checkParity = function(card){//15位转18位card = changeFivteenToEighteen(card);var len = card.length;if(len == '18'){var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');var cardTemp = 0, i, valnum;for(i = 0; i < 17; i ++){cardTemp += card.substr(i, 1) * arrInt[i];}valnum = arrCh[cardTemp % 11];if (valnum == card.substr(17, 1)){return true;}return false;}return false;};//15位转18位⾝份证号changeFivteenToEighteen = function(card){if(card.length == '15'){var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');var cardTemp = 0, i;card = card.substr(0, 6) + '19' + card.substr(6, card.length - 6);for(i = 0; i < 17; i ++){cardTemp += card.substr(i, 1) * arrInt[i];}card += arrCh[cardTemp % 11];return card;}return card;};以上就是本⽂的全部内容,希望对⼤家实现javascript⾝份证校验有所帮助。

C#验证身份证号码正确性的实例代码(收藏)

C#验证身份证号码正确性的实例代码(收藏)

C#验证⾝份证号码正确性的实例代码(收藏)今天在QQ空间看到⼀篇关于C#语⾔验证18位⾝份证号码的验证⽅法和实例代码,抽了些时间学习了⼀下,个⼈觉得还不错,所以把它记了下来,⽅便以后使⽤!18位号码:private static bool CheckIDCard18(string Id){long n = 0;if (long.TryParse(Id.Remove(17), out n) == false || n < Math.Pow(10, 16) || long.TryParse(Id.Replace('x', '0').Replace('X', '0'), out n) == false){return false;}string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91"; if (address.IndexOf(Id.Remove(2)) == -1){return false;}string birth = Id.Substring(6, 8).Insert(6, "-").Insert(4, "-");DateTime time = new DateTime();if (DateTime.TryParse(birth, out time) == false){return false;}string[] arrVarifyCode = ("1,0,x,9,8,7,6,5,4,3,2").Split(',');string[] Wi = ("7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2").Split(',');char[] Ai = Id.Remove(17).ToCharArray();int sum = 0;for (int i = 0; i < 17; i++){sum += int.Parse(Wi[i]) * int.Parse(Ai[i].ToString());}int y = -1;Math.DivRem(sum, 11, out y);if (arrVarifyCode[y] != Id.Substring(17, 1).ToLower()){return false;}return true;//正确}15位号码:private static bool CheckIDCard15(string Id){long n = 0;if (long.TryParse(Id, out n) == false || n < Math.Pow(10, 14)){return false;}string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91"; if (address.IndexOf(Id.Remove(2)) == -1){return false;}string birth = Id.Substring(6, 6).Insert(4, "-").Insert(2, "-");DateTime time = new DateTime();if (DateTime.TryParse(birth, out time) == false){return false;}return true;//正确}总结以上所述是⼩编给⼤家介绍的C#验证⾝份证号码是否正确,希望对⼤家有所帮助,如果⼤家有任何疑问请给我留⾔,⼩编会及时回复⼤家的。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
'VB软件源代码,身份证效验VB代码 把此代码直接复制到工程里运行即可。
Option Explicit
Dim W(16) As Integer '7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2
Dim I As Integer, J As Integer
Private Sub Command1_Click()
Print sfz
Print IIf(SFZyz(sfz), "Y", "N")
Next
Else
MsgBox "输入错误!"
End If
End Sub
Private Sub Form_Load()
W(0) = 7 '把加权因子放入W()数组
W(1) = 9:W(2) = 10:W(3) = 5:W(4) = 8:W(5) = 4:W(6) = 2:W(7) = 1:W(8) = 6:W(9) = 3
Dim Y As Integer, S As Long, Y1 As String
For I = 0 To 16 '对前17位数字的权求和
S = S + Val(Mid(ID, I + 1, 1)) * W(I)
Next
Y = S Mod 11 '对S取模
'Y 0 1 2 3 4 5 6 7 8 9 10
'校验码: 1 0 X(大写) 9 8 7 6 5 4 3 2
Select Case Y '得到校验码
Case 0
Y1 = "1"
Case 1
Y1 = "0"
Case 2
Y1 = "X"
Caห้องสมุดไป่ตู้e 3
Y1 = "9"
Case 4
Y1 = "8"
Case 5
Y1 = "7"
Case 6
Y1 = "6"
Case 7
Y1 = "5"
Case 8
Y1 = "4"
Case 9
Y1 = "3"
Case 10
Y1 = "2"
End Select
SFZyz = (Right(ID, 1) = Y1) '如果身份证号最后一位和校验码相同,函数就返回TRUE,否则返回FALSE
Cls
Dim a As Integer, sfz As String
a = Val(InputBox("输入要判断的身份证的数量(小于1000):"))
If a > 0 And a < 1000 Then
Print a
For J = 1 To a
sfz = UCase(InputBox("输入身份证号:")) '输入身份证号,转换为大写
End Function
W(10) = 7:W(11) = 9:W(12) = 10:W(13) = 5:W(14) = 8:W(15) = 4:W(16) = 2
'For I = 0 To 16 '加权因子可以这样求
'W(I) = 2 ^ (17 - I) Mod 11
'Next
End Sub
Function SFZyz(ID As String) '验证身份证号的函数,参数ID是身份证号
相关文档
最新文档