身份证验证
2007-10-08 00:07
204 查看
function IDCheck(e: string): Boolean;
var
arrVerifyCode, Wi, Checker: TStringList;
Ai: string;
strYear, strMonth, strDay, BirthDay: string;
i, TotalmulAiWi, modValue: Integer;
strVerifyCode: string;
begin
arrVerifyCode := SplitString('1,0,x,9,8,7,6,5,4,3,2', ',');
Wi := SplitString('7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2', ',');
Checker := SplitString('1,9,8,7,6,5,4,3,2,1,1', ',');
if (Length(e) < 15) or (Length(e) = 17) or (Length(e) > 18) then
begin
result := False; //IDCheck= "身份证号共有 15 位或16位或18位"
Exit;
end;
if (Length(e) = 16) and ((not IsNumerice(Copy(e, 16, 1))) and (LowerCase(Copy(e, 16, 1)) <> 'x')) then
begin
result := False; //IDCheck= "身份证号16位或最后一位为数值或X"
Exit;
end;
if Length(e) = 18 then
begin
Ai := Copy(e, 1, 17);
end
else
begin
Ai := e; //15,16位身份证
Ai := Copy(Ai, 1, 6) + '19' + Copy(Ai, 7, 9);
end;
if not IsNumerice(Ai) then
begin
Result := False; //IDCheck= "身份证除最后一位外,必须为数字!"
Exit;
end;
strYear := Copy(Ai, 7, 4);
strMonth := Copy(Ai, 11, 2);
strDay := Copy(Ai, 13, 2);
BirthDay := Trim(strYear) + '-' + Trim(strMonth) + '-' + Trim(strDay);
if IsDate(BirthDay) then
begin
// ShowMessage(IntToStr( Now - StrToDate(BirthDay))); 1790 2007
if (StrToInt(Copy(FormatDateTime('YYYY-MM-DD', Now), 1, 4)) - StrToInt(strYear) > 100) or (strtoDateTime(BirthDay) > date) then
begin
result := False; //IDCheck= "身份证输入错误!" 352625185012035477
Exit;
end;
end
else
begin
result := False; //IDCheck= "身份证输入错误!"
Exit;
end;
for i := 0 to 16 do
begin
TotalmulAiWi := TotalmulAiWi + StrToInt(Copy(Ai, i + 1, 1)) * StrToInt(Wi[i]);
end;
modValue := TotalmulAiWi mod 11;
strVerifyCode := arrVerifyCode[modValue];
Ai := Ai + strVerifyCode;
if (Length(e) = 18) and (e <> Ai) then
begin
Result := False; //IDCheck= "身份证号码输入错误!"
Exit;
end;
Result := True;
end;
var
arrVerifyCode, Wi, Checker: TStringList;
Ai: string;
strYear, strMonth, strDay, BirthDay: string;
i, TotalmulAiWi, modValue: Integer;
strVerifyCode: string;
begin
arrVerifyCode := SplitString('1,0,x,9,8,7,6,5,4,3,2', ',');
Wi := SplitString('7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2', ',');
Checker := SplitString('1,9,8,7,6,5,4,3,2,1,1', ',');
if (Length(e) < 15) or (Length(e) = 17) or (Length(e) > 18) then
begin
result := False; //IDCheck= "身份证号共有 15 位或16位或18位"
Exit;
end;
if (Length(e) = 16) and ((not IsNumerice(Copy(e, 16, 1))) and (LowerCase(Copy(e, 16, 1)) <> 'x')) then
begin
result := False; //IDCheck= "身份证号16位或最后一位为数值或X"
Exit;
end;
if Length(e) = 18 then
begin
Ai := Copy(e, 1, 17);
end
else
begin
Ai := e; //15,16位身份证
Ai := Copy(Ai, 1, 6) + '19' + Copy(Ai, 7, 9);
end;
if not IsNumerice(Ai) then
begin
Result := False; //IDCheck= "身份证除最后一位外,必须为数字!"
Exit;
end;
strYear := Copy(Ai, 7, 4);
strMonth := Copy(Ai, 11, 2);
strDay := Copy(Ai, 13, 2);
BirthDay := Trim(strYear) + '-' + Trim(strMonth) + '-' + Trim(strDay);
if IsDate(BirthDay) then
begin
// ShowMessage(IntToStr( Now - StrToDate(BirthDay))); 1790 2007
if (StrToInt(Copy(FormatDateTime('YYYY-MM-DD', Now), 1, 4)) - StrToInt(strYear) > 100) or (strtoDateTime(BirthDay) > date) then
begin
result := False; //IDCheck= "身份证输入错误!" 352625185012035477
Exit;
end;
end
else
begin
result := False; //IDCheck= "身份证输入错误!"
Exit;
end;
for i := 0 to 16 do
begin
TotalmulAiWi := TotalmulAiWi + StrToInt(Copy(Ai, i + 1, 1)) * StrToInt(Wi[i]);
end;
modValue := TotalmulAiWi mod 11;
strVerifyCode := arrVerifyCode[modValue];
Ai := Ai + strVerifyCode;
if (Length(e) = 18) and (e <> Ai) then
begin
Result := False; //IDCheck= "身份证号码输入错误!"
Exit;
end;
Result := True;
end;
相关文章推荐
- 转: C#实现的18位身份证格式验证算法
- 验证身份证Js函数
- Java身份证验证方法
- 表单验证--手机号,身份证,银行卡号
- JAVA代码验证身份证信息
- 验证身份证号方法
- 验证身份证号码Javascript代码
- java验证身份证号码是否有效源代码
- js验证身份证格式
- javascript 电话,QQ,手机,身份证号,邮箱地址,邮政 正则表达式验证代码
- Java 身份证验证(IdCardVerification)
- JS身份证号严格验证,手机号验证,中文验证的正则
- js验证(手机号,身份证,数字,字符,整数,数字与字符汉字的组合等)
- php 验证身份证有效性,根据国家标准GB 11643-1999 15位和18位通用
- js 验证身份证号码
- iOS开发中邮箱,电话号码,身份证,密码,昵称正则表达式验证
- Android 正则表达式验证手机号、姓名(包含少数民族)、身份证号
- 正则严格验证身份证信息
- java字符串应用之18位身份证格式验证
- C#中使用正则表达式验证电话号码、手机号、身份证号、数字和邮编