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.。
sql语句验证身份证号码

sql语句验证身份证号码像这样写个视图就行了:create View eVMutiCardASSelecta.Badge,/doc/084818076.html,,a.DepID,htt p:///doc/084818076.html,pid,a.JobID,a.Status,a.E mpType,a.ReportT o,b.Identification,N'身份证长度不合常理' As RemarkFrom employee bWhere (Len(b.Identification) Not In (15,18)And b.Identification Is Not Null )Or b.Identification is NullUnion AllSelecta.Badge,/doc/084818076.html,,a.DepID,htt p:///doc/084818076.html,pid,a.JobID,a.Status,a.E mpType,a.ReportT o,b.Identification,N'身份证具有无效字符' As RemarkFrom employee bWhere Len(b.Identification) In (15,18)And Isnumeric(Case Len(b.Identification) When 18 Then Substring(b.Identification,1,17)Else b.Identification End) = 0Union AllSelecta.Badge,/doc/084818076.html,,a.DepID,htt p:///doc/084818076.html,pid,a.JobID,a.Status,a.E mpType,a.ReportT o,b.Identification,N'身份证出生日期不合常理' As RemarkFrom employee bWhere Len(b.Identification) In (15,18)And (IsDate(Case When Len(b.Identification)=15 Then '19'+Substring(b.Identification,7,2)+'-'+Substring(b.Identification,9,2)+'-'+Substring(b.Identification,11,2)Else Substring(b.Identification,7,4)+'-'+Substring(b.Identification,11,2)+'-'+Substring(b.Identification,13,2)End)=0Or Not ((Case When Len(b.Identification)=15 Then '19'+Substring(b.Identification,7,2)+'-'+Substring(b.Identification,9,2)+'-'+Substring(b.Identification,11,2)Else Substring(b.Identification,7,4)+'-'+Substring(b.Identification,11,2)+'-'+Substring(b.Identification,13,2)End) Between '1900-01-01' And '2079-06-06'))Union AllSelecta.Badge,/doc/084818076.html,,a.DepID,htt p:///doc/084818076.html,pid,a.JobID,a.Status,a.E mpType,a.ReportT o,b.Identification,N'身份证校验位不正确(第18位与校验不符)' As RemarkFrom employee bWhere (Len(b.Identification) = 18And substring(b.Identification,18,19) <> dbo.GetCheckIDCardCode(b.Identification)And b.Identification Is Not Null)其中跟据国家规定的计算公式,计算18位身份证检验位的dbo.GetCheckIDCardCode如下:CREATE function GetCheckIDCardCode(@sfzh char(18))returns char(1)asbegindeclare @r varchar(2)declare @i intif len(@sfzh) <> 18set @r = 0elseset @i = cast(substring(@sfzh,1,1) as int) * 7+cast(substring(@sfzh,2,1) as int) * 9+cast(substring(@sfzh,3,1) as int) * 10+cast(substring(@sfzh,4,1) as int) * 5+cast(substring(@sfzh,5,1) as int) * 8+cast(substring(@sfzh,6,1) as int) * 4+cast(substring(@sfzh,7,1) as int) * 2+cast(substring(@sfzh,8,1) as int) * 1+cast(substring(@sfzh,9,1) as int) * 6+cast(substring(@sfzh,10,1) as int) * 3 +cast(substring(@sfzh,11,1) as int) * 7 +cast(substring(@sfzh,12,1) as int) * 9 +cast(substring(@sfzh,13,1) as int) * 10 +cast(substring(@sfzh,14,1) as int) * 5 +cast(substring(@sfzh,15,1) as int) * 8 +cast(substring(@sfzh,16,1) as int) * 4 +cast(substring(@sfzh,17,1) as int) * 2 set @i = @i - @i/11 * 11set @r = cast((case @iwhen 0 then 1when 1 then 0when 2 then 11when 3 then 9when 4 then 8when 5 then 7when 6 then 6when 7 then 5when 8 then 4when 9 then 3when 10 then 2else '' end) as char)if (@r = 11) set @r='X'else set @r = @rset @r = '' + @r +''return @rend。
sql server 常用系统函数

sql server 常用系统函数SQL Server是一款常用的关系型数据库管理系统,它提供了许多强大的系统函数来方便开发人员进行数据处理和管理。
本文将介绍SQL Server常用的系统函数,包括日期时间函数、字符串函数、数学函数、聚合函数等。
一、日期时间函数1. GETDATE():获取当前日期时间。
2. DATEADD():在日期上进行加减操作。
3. DATEDIFF():计算两个日期之间的差值。
4. DATEPART():从日期中提取特定部分的值,如年、月、日、小时、分钟等。
5. CONVERT():将日期时间类型转换为其他类型(如字符串)。
二、字符串函数1. LEN():获取字符串长度。
2. LEFT()、RIGHT()、SUBSTRING():获取字符串的左、右、子字符串。
3. REPLACE():替换字符串中的指定子串。
4. CHARINDEX():查找指定子串在字符串中的位置。
5. LTRIM()、RTRIM():去除字符串左右两侧的空格。
三、数学函数1. ABS():获取绝对值。
2. ROUND()、CEILING()、FLOOR():对数值进行四舍五入、向上取整、向下取整。
3. SIGN():获取数值的符号。
4. POWER()、SQRT()、EXP()、LOG():进行数值计算和运算。
四、聚合函数1. AVG()、SUM()、MIN()、MAX():对一组数据进行平均值、求和、最小值、最大值的计算。
2. COUNT():计算一组数据中元素的个数。
以上是SQL Server常用的系统函数,它们可以方便地进行数据处理和管理,提高开发效率和数据处理的准确性。
在实际应用中,可以根据具体的需求选择合适的函数,进行灵活的数据处理和操作。
18位身份证号码验证公式及标准

18位身份证号码验证工具
计算依据及说明
根据《中华人民共和国国家标准》(GB 11643-1999)规定:
公民身份号码是特征组合码,由十七位数字本体码和一位数字校验码组成。
排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码。
地址码(1-6位):表示编码对象常住户口所在县(市、旗、区)的行政区划代码
生日码(7-14位):表示编码对象出生的年、月、日,其中年份用四位数字表示,年、月、日之间不用分隔符。
例如:1981年05月11日就用19810511表示。
顺序码(15-17位):为同一地址码所标识的区域范围内,对同年、月、日出生的人员编定的顺序号。
其中奇数分给男性,偶数分给女性。
校验码(18位):是根据前面十七位数字码,按照ISO 7064:1983.MOD 11-2校验码计算出来的检验码。
第十八位数字的计算方法为:
1.将前面的身份证号码17位数分别乘以不同的权数。
从第一位到第十七位的权数分别为:7、9、10、5、8、4、2、1、6、3、7、9、10、5、8、4、2。
2.将这17位数字和其对应的权数分别相乘并加总。
3.用加总来和除以11,看余数是多少?
4余数只可能有0 1 2 3 4 5 6 7 8 9 10这11个数字。
其分别对应的最后一位身份证的号码为1 0 X 9 8 7 6 5 4 3 2。
5.通过上面得知,如果余数是2,就会在身份证的第18位数字上出现罗马数字的Ⅹ。
如果余数是10,身份证的最后一位号码就是2。
以上算法来源于网络,具体规范见国家相关标准。
身份证重复查询函数公式

身份证重复查询函数公式
身份证重复查询函数公式是指用算法来检测身份证号码在一个或多个指定的数据库中中是否存在重复。
采用这种方法能够及早发现身份证号码重复出现,以避免出现不良后果。
1、校验规则:首先,使用身份证号码重复查询函数进行身份证号码校验,检查号码中的字符是否合法,号码的总位数是否正确等;
2、识别重复:使用算法检查一个或多个指定的数据库中是否存在身份证号码的重复,如果出现问题,立即发出警报;
3、处理措施:如果发现生成身份证号码重复,应该立即采取适当的措施处理:首先,只有确认身份信息无误后,才能更新或替换身份证号码,以保障其唯一性;其次,如果发现真实存在两个相同的身份证号码,则需要确认其真实者,只有确认真实者之后才能更新或替换身份证号码。
4、更新数据:如果发现身份证号码重复,经过确认真实者之后,应当及时更新相应的数据,以避免其重复出现;
5、痕迹清理:发现身份证重复后,需要及时清理记录和痕迹,以防止冒领等相关行为发生。
使用身份证重复查询函数公式是一种有效的防止冒领的方法,它能够短时间内快速准确地发现重复的身份证号码,并能及时采取措施避免造成不良后果。
vb居民身份证 校验函数

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
PHP实现中国公民身份证号码有效性验证示例代码

PHP实现中国公民⾝份证号码有效性验证⽰例代码本⽂将使⽤Java实现中国公民(15位或者18位)⾝份证号码的相关验证,功能如下:1. ⾝份证号有效性验证2. 分析详细⾝份证信息3. ⽣成⼀个虚拟的省份证号码。
⾝份证号码验证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 2IDValidator.php<?phpnamespace com\jdk5\blog\IDValidator;class IDValidator {private static $GB2260;private static $instance;private static $cache = array();private static $util;function __construct() {if (!class_exists("com\jdk5\blog\IDValidator\GB2260")){include 'GB2260.php';}if (!class_exists("com\jdk5\blog\IDValidator\util")){include 'util.php';}self::$GB2260 = GB2260::getGB2260 ();self::$util = util::getInstance();}public static function getInstance() {if (is_null ( self::$instance )) {self::$instance = new IDValidator ();}return self::$instance;}function isValid($id) {$code = self::$util->checkArg ( $id );if ($code === false) {return false;}// 查询cacheif (isset ( self::$cache [ $id ] ) && self::$cache [$id] ['valid'] !== false) {return self::$cache [$id] ['valid'];} else {if (! isset ( self::$cache [ $id ] )) {self::$cache [$id] = array ();}}$addr = substr ( $code ['body'], 0, 6 );$birth = $code ['type'] === 18 ? substr ( $code ['body'], 6, 8 ) :substr ( $code ['body'], 6, 6 );$order = substr ( $code ['body'], - 3 );if (! (self::$util->checkAddr ( $addr ) && self::$util->checkBirth ( $birth ) &&self::$util->checkOrder ( $order ))) {self::$cache [$id] ['valid'] = false;return false;}// 15位不含校验码,到此已结束if ($code ['type'] === 15) {self::$cache [$id] ['valid'] = true;/* 校验位部分 */// 位置加权$posWeight = array ();for($i = 18; $i > 1; $i --) {$wei = self::$util->weight ( $i );$posWeight [$i] = $wei;}// 累加body部分与位置加权的积$bodySum = 0;$bodyArr = str_split( $code ['body'] );for($j = 0; $j < count ( $bodyArr ); $j ++) {$bodySum += (intval ( $bodyArr [$j], 10 ) * $posWeight [18 - $j]);}// 得出校验码$checkBit = 12 - ($bodySum % 11);if ($checkBit == 10) {$checkBit = 'X';} else if ($checkBit > 10) {$checkBit = $checkBit % 11;}// 检查校验码if ($checkBit != $code ['checkBit']) {self::$cache [$id] ['valid'] = false;return false;} else {self::$cache [$id] ['valid'] = true;return true;}}// 分析详细信息function getInfo ($id) {// 号码必须有效if ($this->isValid($id) === false) {return false;}// TODO 复⽤此部分$code = self::$util->checkArg($id);// 查询cache// 到此时通过isValid已经有了cache记录if (isset(self::$cache[$id]) && isset(self::$cache[$id]['info'])) {return self::$cache[$id]['info'];}$addr = substr($code['body'], 0, 6);$birth = ($code['type'] === 18 ? substr($code['body'], 6, 8) :substr($code['body'], 6, 6));$order = substr($code['body'], -3);$info = array();$info['addrCode'] = $addr;if (self::$GB2260 !== null) {$info['addr'] = self::$util->getAddrInfo($addr);}$info ['birth'] = ($code ['type'] === 18 ? (substr ( $birth, 0, 4 ) . '-' . substr ( $birth, 4, 2 ) . '-' . substr ( $birth, - 2 )) : ('19' . substr ( $birth, 0, 2 ) . '-' . substr ( $birth, 2, 2 ) . '-' . substr ( $birth, - 2 ))); $info['sex'] = ($order % 2 === 0 ? 0 : 1);$info['length'] = $code['type'];if ($code['type'] === 18) {$info['checkBit'] = $code['checkBit'];}// 记录cacheself::$cache[$id]['info'] = $info;return $info;}// 仿造⼀个号function makeID ($isFifteen=false) {// 地址码$addr = null;if (self::$GB2260 !== null) {$loopCnt = 0;while ($addr === null) {// 防⽌死循环if ($loopCnt > 50) {$addr = 110101;break;}$prov = self::$util->str_pad(self::$util->rand(66), 2, '0');$city = self::$util->str_pad(self::$util->rand(20), 2, '0');$area = self::$util->str_pad(self::$util->rand(20), 2, '0');$addrTest = $prov . $city . $area;if (isset(self::$GB2260[$addrTest])) {$addr = $addrTest;break;}$loopCnt ++;}} else {// 出⽣年$yr = self::$util->str_pad(self::$util->rand(99, 50), 2, '0');$mo = self::$util->str_pad(self::$util->rand(12, 1), 2, '0');$da = self::$util->str_pad(self::$util->rand(28, 1), 2, '0');if ($isFifteen) {return $addr . $yr . $mo . $da. self::$util->str_pad(self::$util->rand(999, 1), 3, '1');}$yr = '19' . $yr;$body = $addr . $yr . $mo . $da . self::$util->str_pad(self::$util->rand(999, 1), 3, '1');// 位置加权$posWeight = array();for ($i = 18; $i > 1; $i--) {$wei = self::$util->weight($i);$posWeight[$i] = $wei;}// 累加body部分与位置加权的积$bodySum = 0;$bodyArr = str_split($body);for ($j = 0; $j < count($bodyArr); $j++) {$bodySum += (intval($bodyArr[$j], 10) * $posWeight[18 - $j]);}// 得出校验码$checkBit = 12 - ($bodySum % 11);if ($checkBit == 10) {$checkBit = 'X';} else if ($checkBit > 10) {$checkBit = $checkBit % 11;}return ($body . $checkBit);}}调⽤<?phpheader("Content-type: text/html; charset=utf-8");include 'IDValidator.php';$v = com\jdk5\blog\IDValidator\IDValidator::getInstance();//⽣成⼀个18位⾝份证号$id = $v->makeID();//获取⾝份证信息$info = $v->getInfo($id);var_dump($info);//⽣成⼀个15位⾝份证号$id = $v->makeID(true);$info = $v->getInfo($id);var_dump($info);//验证⾝份证号是否正确var_dump($v->isValid("123456789012345678"));以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
SqlServer中批量update语句

SqlServer中批量update语句现在我有两张表分别是S_PERSON,S_USERS_PERSONS_USER我现在想把S_USER表中的ACCOUNT批量修改成S_PERSON的ACCOUNT我们可以发现S_USER表中有个跟S_PERSON表关联的字段那就是PERSON_ID 这也是我们要update的条件找到这个关系以后我们就不难写sql了update S_USER set account=p.account from S_PERSON p where p.id=S_USER.person_id;结果为:sqlserver as 语法举例1、使⽤表名称别名有两个表分别是:"Persons" 和 "Product_Orders"。
分别为它们指定别名 "p" 和 "po"。
列出 "John Adams" 的所有定单。
SELECT po.OrderID, stName, p.FirstNameFROM Persons AS p, Product_Orders AS poWHERE stName='Adams' AND p.FirstName='John';2、使⽤列名称别名查询 Persons 表中的 LastName 列(为其定义别名 '姓⽒')和 FirstName 列(为其定义别名 ‘名字'),输出所有结果值。
SELECT LastName AS 姓⽒, FirstName AS 名字FROM Persons3、同时使⽤表名称和列名称为 city 表定义别名 'A',并利⽤该表别名查询表中的 ID 列(为ID列定义别名 B)的所有信息。
SELECT A.ID AS BFROM city AS A;这篇⽂章就介绍到这了,希望能帮助到你。
18位身份证和组织机构代码校验ORACLE函数

18位身份证和组织机构代码校验ORACLE函数第一篇:18位身份证和组织机构代码校验ORACLE函数18位身份证和组织机构代码校验ORACLE函数18位身份证和组织机构代码校验ORACLE函数18位身份证标准在国家质量技术监督局于1999年7月1日实施的GB11643-1999《公民身份号码》中做了明确规定。
GB11643-1999《公民身份号码》为GB11643-1989《社会保障号码》的修订版,其中指出将原标准名称“社会保障号码”更名为“公民身份号码”,另外GB11643-1999《公民身份号码》从实施之日起代替GB11643-1989。
公民身份号码是特征组合码,由十七位数字本体码和一位校验码组成。
排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位校验码。
其含义如下:1.地址码:表示编码对象常住户口所在县(市、旗、区)的行政区划代码,按GB/T2260的规定执行。
2.出生日期码:表示编码对象出生的年、月、日,按GB/T7408的规定执行,年、月、日分别用4位、2位、2位数字表示,之间不用分隔符。
3.顺序码:表示在同一地址码所标识的区域范围内,对同年、同月、同日出生的人编定的顺序号,顺序码的奇数分配给男性,偶数分配给女性。
校验的计算方式:1.对前17位数字本体码加权求和公式为:S = Sum(Ai * Wi), i = 0,..., 16其中Ai表示第i位置上的身份证号码数字值,Wi表示第i位置上的加权因子,其各位对应的值依次为: 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 22.以11对计算结果取模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 215位的身份证号dddddd yymmdd xx p18位的身份证号dddddd yyyymmdd xx p y其中dddddd为地址码(省地县三级)18位中的和15位中的不完全相同 yyyymmdd yymmdd 为出生年月日 xx顺号类编码 p性别18位中末尾的y为校验码,在网上可以找到算法(1)、前两个数字代表省份编码。