SQLServer中获取18位身份证号码校验码的函数
如何利用Visual Basic开发身份证号码批量验证工具软件

[]822013.1探索【信息技术课堂】通过对身份证号码实际应用中存在的问题进行详细分析,我们发现每学年的学籍建档、国家助学金申报等方面都离不开身份证号码。
同时,人工核对信息工作量大,也易出错,势必对工作造成一定的影响。
为此,我们运用大学学习的一些VB 知识,根据身份证号码编码规则编写了《身份证号码批量验证工具》软件,使身份证号码核对工作变得简单、轻松。
一、软件的设计步骤二、软件详细设计1.解决方案与软件特色本程序使用VB 在Windows XP 环境开发,解决了身份证号码验证过程中存在的易出错、工作量大的问题,支持Excel 文件批量验证及信息追加,绿色免安装、小巧、实用性强。
2.具体设计下面就根据软件的操作流程图进行介绍软件的功能和实现原理:(1)操作流程图。
参数设置说明:身份证号码、性别、出生年月所在列均以阿拉伯数字表示,性别、出生年月信息的追加属于选择项。
(2)身份证号码校验值计算函数代码。
Public Function sfzjym(num As String)As StringDim n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,y,s As Integern1=Val(Mid$(num,1,1))*7n2=Val(Mid$(num,2,1))*9n3=Val(Mid$(num,3,1))*10n4=Val(Mid$(num,4,1))*5n5=Val(Mid$(num,5,1))*8n6=Val(Mid$(num,6,1))*4n7=Val(Mid$(num,7,1))*2n8=Val(Mid$(num,8,1))*1n9=Val(Mid$(num,9,1))*6n10=Val(Mid$(num,10,1))*3n11=Val(Mid$(num,11,1))*7n12=Val(Mid$(num,12,1))*9n13=Val(Mid$(num,13,1))*10n14=Val(Mid$(num,14,1))*5n15=Val(Mid$(num,15,1))*8n16=Val(Mid$(num,16,1))*4n17=Val(Mid$(num,17,1))*2y=n1+n2+n3+n4+n5+n6+n7+n8+n9+n10+n11+n12+n13+n14+n15+n 16+n17s=y Mod 11Select Cases Case 0sfzjym=“1”Case 1sfzjym=“0”Case 2sfzjym=“X”Case 3sfzjym=“9”Case 4sfzjym=“8”Case 5sfzjym=“7”Case 6sfzjym=“6”Case 7sfzjym=“5”Case 8sfzjym=“4”Case 9sfzjym=“3”Case 10sfzjym=“2”End Select End Function函数参数为18位身份证号码,返回值为身份证号码的校验值,即身份证号码最后一位,整个计算过程严格按照GB11643-1999《公民身份号码》中的规定完成。
PHP实现可精确验证身份证号码的工具类示例

PHP实现可精确验证⾝份证号码的⼯具类⽰例本⽂实例讲述了PHP实现可精确验证⾝份证号码的⼯具类。
分享给⼤家供⼤家参考,具体如下:<?phpclass check_IdCard {// $num为⾝份证号码,$checkSex:1为男,2为⼥,不输⼊为不验证public function checkIdentity($num, $checkSex = '') { // 不是15位或不是18位都是⽆效⾝份证号if (strlen($num) != 15 && strlen($num) != 18) {return false;}// 是数值if (is_numeric($num)) {// 如果是15位⾝份证号if (strlen($num) == 15) {// 省市县(6位)$areaNum = substr($num, 0, 6);// 出⽣年⽉(6位)$dateNum = substr($num, 6, 6);// 性别(3位)$sexNum = substr($num, 12, 3);} else {// 如果是18位⾝份证号// 省市县(6位)$areaNum = substr($num, 0, 6);// 出⽣年⽉(8位)$dateNum = substr($num, 6, 8);// 性别(3位)$sexNum = substr($num, 14, 3);// 校验码(1位)$endNum = substr($num, 17, 1);}} else {// 不是数值if (strlen($num) == 15) {return false;} else {//验证前17位为数值,且18位为字符x$check17 = substr($num, 0, 17);if (!is_numeric($check17)) {return false;}//省市县(6位)$areaNum = substr($num, 0, 6);// 出⽣年⽉(8位)$dateNum = substr($num, 6, 8);// 性别(3位)$sexNum = substr($num, 14, 3);// 校验码(1位)$endNum = substr($num, 17, 1);if ($endNum != 'x' && $endNum != 'X') {return false;}}}//验证地区if (isset($areaNum)) {if (!$this->checkArea($areaNum)) {return false;}}//验证⽇期if (isset($dateNum)) {if (!$this->checkDate($dateNum)) {return false;}}// 性别1为男,2为⼥if ($checkSex == 1) {if (isset($sexNum)) {if (!$this->checkSex($sexNum)) {return false;}}} elseif ($checkSex == 2) {if (isset($sexNum)) {if ($this->checkSex($sexNum)) {return false;}}}//验证最后⼀位if (isset($endNum)) {if (!$this->checkEnd($endNum, $num)) {return false;}}return true;}// 验证城市private function checkArea($area) {$num1 = substr($area, 0, 2);$num2 = substr($area, 2, 2);$num3 = substr($area, 4, 2);// 根据GB/T2260—999,省市代码11到65if (10 < $num1 && $num1 < 66) {return true;} else {return false;}}// 验证出⽣⽇期private function checkDate($date) {if (strlen($date) == 6) {$date1 = substr($date, 0, 2);$date2 = substr($date, 2, 2);$date3 = substr($date, 4, 2);$statusY = $this->checkY('19' . $date1); } else {$date1 = substr($date, 0, 4);$date2 = substr($date, 4, 2);$date3 = substr($date, 6, 2);$nowY = date("Y", time());if (1900 < $date1 && $date1 <= $nowY) {$statusY = $this->checkY($date1);} else {return false;}}if (0 < $date2 && $date2 < 13) {if ($date2 == 2) {// 润年if ($statusY) {if (0 < $date3 && $date3 <= 29) {return true;} else {return false;}} else {// 平年if (0 < $date3 && $date3 <= 28) {return true;} else {return false;}}} else {$maxDateNum = $this->getDateNum($date2); if (0 < $date3 && $date3 <= $maxDateNum) { return true;} else {return false;}}} else {return false;}}// 验证性别private function checkSex($sex) {if ($sex % 2 == 0) {return false;} else {return true;}}// 验证18位⾝份证最后⼀位private function checkEnd($end, $num) {$checkHou = array(1, 0, 'x', 9, 8, 7, 6, 5, 4, 3, 2);$checkGu = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);$sum = 0;for ($i = 0;$i < 17;$i++) {$sum+= (int)$checkGu[$i] * (int)$num[$i];}$checkHouParameter = $sum % 11;if ($checkHou[$checkHouParameter] != $num[17]) {return false;} else {return true;}}// 验证平年润年,参数年份,返回 true为润年 false为平年private function checkY($Y) {if (getType($Y) == 'string') {$Y = (int)$Y;}if ($Y % 100 == 0) {if ($Y % 400 == 0) {return true;} else {return false;}} else if ($Y % 4 == 0) {return true;} else {return false;}}// 当⽉天数参数⽉份(不包括2⽉)返回天数private function getDateNum($month) {if ($month == 1 || $month == 3 || $month == 5 || $month == 7 || $month == 8 || $month == 10 || $month == 12) {return 31;} else if ($month == 2) {} else {return 30;}}}// 测试header("content-type:text/html;charset=utf-8");$num = '230106************'; //此号码为随机⽣成$test = new check_IdCard();$data = $test->checkIdentity($num);var_dump($data);//=============新的18位⾝份证号码各位的含义:=======================//1-2位省、⾃治区、直辖市代码;11-65//3-4位地级市、盟、⾃治州代码;//5-6位县、县级市、区代码;//7-14位出⽣年⽉⽇,⽐如19670401代表1967年4⽉1⽇;//15-17位为顺序号,其中17位男为单数,⼥为双数;//18位为校验码,0-9和X,由公式随机产⽣。
SQLServer中几个有用的特殊函数

SQLServer中⼏个有⽤的特殊函数在SQL Server 的使⽤过程中,发现⼏个很有⽤,但不太常⽤(或细节不太清楚)的函数(存储过程):isnumeric,isdate,patindex,newid,collate,sp_executesql,checksum遂记下,以备⽇后查询。
不敢独享,与君共之。
有⽤且看,⽆⽤略过。
1> isnumeric( expression )-- 返回值 1 | 0,判断是否是数字类型。
数值类型包括(int、bigint、smallint、tinyint、numeric、money、smallmoney、float、decimal、real)⽰例:select * from tablenamewhere isnumeric(columnname)<> 1;go以上⽰例使⽤ isnumeric 返回所有⾮数值的数据⾏。
2> isdate( expression )-- 如果 expression 是有效的 date、time 或 datetime 值,则返回 1;否则返回 0。
⽰例:if isdate('2009-05-12 10:19:41.177') = 1print '有效的⽇期'elseprint '⽆效的⽇期'上⾯的⽰例使⽤ isdate 测试某⼀字符串是否是有效的 datetime。
3> patindex( '%pattern%' , expression )-- 返回指定表达式中某模式第⼀次出现的起始位置;-- 如果在全部有效的⽂本和字符数据类型中没有找到该模式,则返回零。
'pattern' :⼀个通配符字符串。
pattern 之前和之后必须有 % 字符(搜索第⼀个或最后⼀个字符时除外)。
expression :通常为要在其中搜索指定模式的字符串数据类型列。
ORACLE对身份证号码处理的相关SQL汇总

ORACLE对身份证号码处理相关的SQL汇总身份证号码算法及应用场景:工作实践总结,与大家分享快乐,并请高人批评指正,努力改进:目前我国大量存在着正在有效期的15位身份证,虽然国家在推行二代身份证,但尚未发现强行要求全国人民更换未到期的15位身份证的官方声明或公告。
扯远了:),总之合法的15位身份证号码将在今后一段时间内继续存在下去。
另外,项目中往往有着大量的历史数据,我们的一个系统中15位身份证所占比重很大,因此系统必须实现对两套身份证编码的职能处理,并支持另外一种特殊证件类型:军官证/警官证。
本文重点讨论15位/18位身份证的处理问题众所周知,我们现执行的身份证号码编码由公安部具体落实编码规则,有15位/18位两种,公安部以数学语言描述的方式公开了身份证编码规则和位码含义,但具体到计算机语言实现,需要开发人员自行根据算法设计。
本文主要以oracle的SQL为例子,其他语言大家可以自行转换,道理都是一样的。
这里以ORACLE为例,其他数据库类似:CREATE OR REPLACE function ID15TO18(p_OldID varchar2) return varchar2 istype TIArray is table of integer;type TCArray is table of char(1);Result varchar2(18);W TIArray;A TCArray;S integer;beginif Length(p_OldID) <> 15 OR NOT ISIDCARD(p_OldID) thenraise_application_error(-20999, '不是旧15位身份证号或者不是身份证号');Result := p_OldID;elseW := TIArray(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1);A := TCArray('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');Result := SubStr(p_OldID, 1, 6) || '19' || SubStr(p_OldID, 7, 9);S := 0;beginfor i in 1 .. 17 loopS := S + to_number(SubStr(Result, i, 1)) * W(i);end loop;exceptionwhen others thenreturn '';end;S := S mod 11;Result := Result || A(s + 1);end if;return(Result);end ID15TO18;/CREATE OR REPLACE function isIDCard(p_IDcard varchar2) return boolean isIDcardlen integer;beginIDcardlen :=Length(p_IDcard);/*if (IDcardlen = 18 and IS_NUMBER(SubStr(p_IDcard, 1, IDcardlen-1))and IS_DATE (substr(p_IDcard,7,8)))or(IDcardlen = 15 and IS_NUMBER(SubStr(p_IDcard, 1, IDcardlen))and IS_DATE ('19' || subsTR(p_IDcard,7,6)))*/if (IDcardlen = 18)or(IDcardlen = 15 )thenreturn TRUE;ELSEreturn FALSE;end if;end isIDCard;/CREATE OR REPLACE FUNCTION is_number (str IN VARCHAR2)RETURN NUMBERISBEGINIF str IS NULLTHENRETURN 0;ELSEIF regexp_like (str, '^(-{0,1} {0,1})[0-9] (.{0,1}[0-9] )$')THENRETURN 1;ELSERETURN 0;END IF;END IF;END is_number;/CREATE OR REPLACE function getAge(p_IDcard varchar2) return integer is IDcardlen integer;IDcardyear integer;beginIDcardlen :=Length(p_IDcard);if isidcard(p_IDcard) and IDcardlen = 18 thenIDcardyear := to_number(substr(p_IDcard,7,4));end if;if isidcard(p_IDcard) and IDcardlen = 15 thenIDcardyear := to_number('19'||substr(p_IDcard,7,2));end if;return to_number(to_char(sysdate,'yyyy'))-IDcardyear;end getAge;/CREATE OR REPLACE function getSex(p_IDcard varchar2) return varchar2 is IDcardlen integer;beginIDcardlen :=Length(p_IDcard);if not isidcard(p_IDcard)thenreturn null;end if;if IDcardlen = 18 and Substr(p_IDcard,17,1) in (1,3,5,7,9) then return ('男');end if;if IDcardlen = 18 and Substr(p_IDcard,17,1) in (2,4,6,8,0)then return ('女');end if;if IDcardlen = 15 and Substr(p_IDcard,15,1) in (1,3,5,7,9) then return ('男');end if;if IDcardlen = 15 and Substr(p_IDcard,15,1) in (2,4,6,8,0)then return ('女');end if;end getSex;//* Formatted on 2009/05/22 13:35 (Formatter Plus v4.8.6) */ CREATE OR REPLACE FUNCTION is_date (in_date IN VARCHAR2) RETURN BOOLEANISv_date_value DATE;invalid_day EXCEPTION;invalid_month EXCEPTION;PRAGMA EXCEPTION_INIT (invalid_day, -1839);PRAGMA EXCEPTION_INIT (invalid_month, -1843);BEGINSELECT TO_DATE (in_date, 'YYYY-MM-DD')INTO v_date_valueFROM DUAL;RETURN TRUE;EXCEPTIONWHEN invalid_dayTHENRETURN FALSE;WHEN invalid_monthTHENRETURN FALSE;WHEN OTHERSTHENRETURN FALSE;END is_date;/。
函数自动提取身份证号码信息

函数自动提取身份证号码信息大家知道,目前的身份证号码有两种格式,一种是15位号码(如340501*********),一种是18位号码(如340503************)。
在15位号码中,第7—12位数字(如761217)表示持证人的出生时间(如1976年12月17日),第15位数字(如2)表示持证人的性别(奇数为“男”,偶数为“女”);在18位号码中,第7—14位数字(如19700109)表示持证人的出生时间(如1970年1月9日),第17位数字(如1)表示持证人的性别。
一、信息的提取、判断和自动显示此处,假定身份证号码保存在C列中,性别和出生时间分别保存在D列和E列中。
1、性别的自动显示2、①选中D2单元格,输入公式:=IF(MOD(IF(LEN(C2)=15,MID(C2,15,1),MID(C2,17,1)),2)=0,"女","男"),输入完成后,按下“Enter”键进行确认,第1位员工的性别则自动显示在D2单元格中[如图1]。
上述函数式中涉及到的几个函数的含义分别是:LEN(C2)函数,用于统计C2单元格中字符串的字符数目。
MID(C2,15,1)函数,用于从C2单元格中字符串的第15位开始提取1个字符。
MOD(number,divisor)函数,用于给出数字number除以数字divisor后的余数。
IF()函数,是一个逻辑判断函数。
上述函数式的意思是:IF(LEN(C2)=15,MID(C2,15,1),MID(C2,17,1)):如果[IF]C2单元格中字符串的字符数是15[LEN(C2)=15],则从第15位开始,提取C2单元格字符串中的1个字符[MID(C2,15,1)];如果不是15位,则从第17位开始,提取1个字符[MID(C2,17,1)]。
=IF(MOD(IF(LEN(C2)=15,MID(C2,15,1),MID(C2,17,1)),2)=0,"女","男"):如果[IF]提取出来的数值[IF(LEN(C2)=15,MID(C2,15,1),MID(C2,17,1))]除以“2”后余数为“0”[MOD(IF(LEN(C2)=15,MID(C2,15,1),MID(C2,17,1)),2)=0],则显示为“女”,反之显示为“男”。
身份证15位转18位(SQL函数)

⾝份证15位转18位(SQL函数)USE [您的数据库名]GO/****** Object: UserDefinedFunction [dbo].[get18id] Script Date: 10/10/2014 16:32:15 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author:-- Create date:-- Description:-- =============================================CREATE FUNCTION [dbo].[get18id](-- Add the parameters for the function here@id nvarchar(18))RETURNS nvarchar(18)ASBEGIN-- Declare the return variable hereDECLARE @myresult nvarchar(18),@ids nvarchar(17),@idindex int,@idsum int,@idcharnumber tinyint,@idmod int,@idlast char-- check input rightif(@id is null or @id='')beginRETURN nullendif(LEN(@id)<>15)beginif(LEN(@id)<>18)beginreturn nullendreturn @idendset @idindex=1;-- birthday year defoult is '19'set @ids=SUBSTRING(@id,1,6)+'19'+SUBSTRING(@id,7,9);--RETURN @ids;while(@idindex<=18)beginset @idcharnumber=convert(tinyint,SUBSTRING(@ids,@idindex,1));--return @idcharnumber;--print @idcharnumber+'\n';if(@idindex=1)beginset @idsum=7*@idcharnumber;--return @idsum;endelse if(@idindex=2)beginset @idsum+=9*@idcharnumber;endelse if(@idindex=3)beginset @idsum+=10*@idcharnumber; endelse if(@idindex=4)beginset @idsum+=5*@idcharnumber; endelse if(@idindex=5)beginset @idsum+=8*@idcharnumber; endelse if(@idindex=6)beginset @idsum+=4*@idcharnumber; endelse if(@idindex=7)beginset @idsum+=2*@idcharnumber; endelse if(@idindex=8)beginset @idsum+=1*@idcharnumber; endelse if(@idindex=9)beginset @idsum+=6*@idcharnumber; endelse if(@idindex=10)beginset @idsum+=3*@idcharnumber; endelse if(@idindex=11)beginset @idsum+=7*@idcharnumber; endelse if(@idindex=12)beginset @idsum+=9*@idcharnumber; endelse if(@idindex=13)beginset @idsum+=10*@idcharnumber; endelse if(@idindex=14)beginset @idsum+=5*@idcharnumber; endelse if(@idindex=15)beginset @idsum+=8*@idcharnumber; endelse if(@idindex=16)beginset @idsum+=4*@idcharnumber; endelse if(@idindex=17)beginset @idsum+=2*@idcharnumber; endset @idindex=@idindex+1;--break;end--return @idsum;set @idmod=@idsum%11;if(@idmod=0)beginset @idlast='1';endelse if(@idmod=1)beginset @idlast='0';endelse if(@idmod=2)beginset @idlast='X';endelse if(@idmod=3)beginset @idlast='9';endelse if(@idmod=4)beginset @idlast='8';endelse if(@idmod=5)beginset @idlast='7';endelse if(@idmod=6)beginset @idlast='6';endelse if(@idmod=7)beginset @idlast='5';endelse if(@idmod=8)beginset @idlast='4';endelse if(@idmod=9)beginset @idlast='3';endelse if(@idmod=10)beginset @idlast='2';endset @myresult=@ids+@idlast; -- Return the result of the function RETURN @myresultENDGO。
sql server使用函数

sql server使用函数
SQLServer中的函数是一种可重复使用的代码块,可以接收输入参数并返回一个值或表。
它们是SQL Server编程中的重要组成部分,用于简化复杂的查询和数据操作。
以下是一些常见的SQL Server函数:
1. 聚合函数:在查询中使用聚合函数可以计算数据的总和、平均值、最大值、最小值等。
常见的聚合函数包括SUM、AVG、MAX、MIN、COUNT等。
2. 字符串函数:SQL Server提供了许多函数来操作字符串,如LEN、LEFT、RIGHT、SUBSTRING、CHARINDEX等。
这些函数可以在字符串中查找、替换、截取和连接字符。
3. 日期和时间函数:日期和时间函数可用于格式化日期和时间值、计算日期之间的差异以及执行其他日期和时间操作。
常见的日期和时间函数包括GETDATE、DATEADD、DATEDIFF、DATEPART等。
4. 数学函数:SQL Server还提供了许多数学函数,如ABS、ROUND、CEILING、FLOOR、POWER等。
这些函数可用于执行各种数学计算,如绝对值、舍入、取整和幂运算。
SQL Server函数可以嵌套使用和组合,以执行更复杂的查询和数据操作。
使用函数可以减少代码量,提高查询和数据操作的效率和可读性。
- 1 -。
身份证号码有效性校验程序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.。