16,747
社区成员




'//所有的函数用VB语言声明,用PbScript书写
'////////////////////////////由身份证号获取生日
public function card_id_birth (byval string p_card_id) as date
date birth
If len(trim(p_card_id)) = 15 Then
birth = date("19"+Mid(p_card_id,7,2)+"-"+&
Mid(p_card_id,9,2)+"-"+Mid(p_card_id,11,2))
ElseIf len(trim(p_card_id)) = 18 Then
birth = date(Mid(p_card_id,7,4)+"-"+&
Mid(p_card_id,11,2)+"-"+Mid(p_card_id,13,2))
End If
If birth = date("1900-01-01") then
messagebox("输入错误","身份证号码中关于出生年月的信息不对!",Exclamation!,ok!)
// sle_card_id.setfocus()
Return 1900-01-01
End If
return birth
end function
'///////////////////////////////////////////////////////////
'由身份证号获取性别
public function card_id_sex(byval p_card_id as string)
integer I_card_num
If len(p_card_id) = 15 Then
I_card_num = Integer(Right(p_card_id,1))
ElseIf len(p_card_id) = 18 Then
I_card_num = Integer(Mid(p_card_id,17,1))
Else
messagebox("注意","身份证号码输入有误,请重试!",Exclamation!,ok!)
Return string(3)
End If
If Mod(I_card_num,2) = 0 Then
Return string(2) //女
Else
Return string(1)
End If
end function
//ID:身份证号。身份证输入异常,或者为女性时返回False,否则返回True
function card_id_sex(ID: string): boolean;
var
I: integer;
begin
Result:=False;
if Length(ID)=18 then
I:=17
else if Length(ID)=15 then
I:=15
else Exit;
if TryStrToInt(ID[I],I) then
Result:=Odd(I);
end;
//ID:身份证号。身份证输入异常,返回'1899-12-31',否则返回身份证的生日
function card_id_birth(ID: string): TDateTime;
var
S:string;
ADate:TDateTime;
begin
Result:=0;
if Length(ID) = 15 then
S:=Format('19%s-%s-%s',[Copy(ID,7,2),Copy(ID,9,2),Copy(ID,11,2)])
else if Length(ID) = 18 then
S:=Format('%s-%s-%s',[Copy(ID,7,4),Copy(ID,11,2),Copy(ID,13,2)])
else Exit;
if TryStrToDate(S,ADate) then
Result:=ADate;
end;
function CheckSFZZ(const sfzh:string; var csrq:string;var xb:string):string;
function idcard_verify_number(idcard_base:string):char;
const
factor:array [1..17] of integer =(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
verify_number_list = '10X98765432';
var
checksum,i,mods:integer;
begin
result:=#0;
if length(idcard_base) = 17 then
begin
checksum := 0;
for i := 1 to length(idcard_base) do
checksum :=checksum + strtoint(idcard_base[i]) * factor[i];
mods := checksum mod 11+1;
result := verify_number_list[mods];
end;
end;
var
cs,s,s1,ret:string;
l,i,m:integer;
c:char;
begin
result:='';
ret:='';
s:=SFZH;
l:=Length(s);
try
case l of
15:
begin
i:=StrToInt(RightStr(s,1));
cs:='19'+copy(s,7,2)+'.'+copy(s,9,2)+'.'+copy(s,11,2);
m:=Strtoint(copy(s,13,3));
if m >= 996 then
s1:=copy(s,1,6)+'18'+copy(s,7,9)
else
s1:=copy(s,1,6)+'19'+copy(s,7,9);
ret:=s1+idcard_verify_number(s1);
end;
18:
begin
i:=StrToInt(copy(s,17,1));
cs:=copy(s,7,4)+'.'+copy(s,11,2)+'.'+copy(s,13,2);
s1:=leftstr(s,17);
c:=idcard_verify_number(s1);
if c<>s[18] then
raise EMathError.Create('error');
ret:=s;
end;
else
raise EMathError.Create('error');
end;
except
exit;
end;
if i mod 2=0 then
XB:='2'
else
XB:='1';
if tutils.IsValidDate(cs) then
begin
CSRQ:=cs;
result:=ret;
end else
result:='';
end;
function card_id_birth(s:string):Tdate;
var
i:integer;
str: string;
begin
if not (length(s) in [15,18]) then
begin
showmessage(' ');
result:=strtodate('1900-01-01');
end;
if length(s)=15 then
begin
str:='19'+copy(s,7,2)+'-'+copy(s,9,2)+'-'+copy(s,11,2);
result:=strtodate(str);
end;
if length(s)=18 then
begin
str:=copy(s,7,4)+'-'+copy(s,11,2)+'-'+copy(s,13,2);
result:=strtodate(str);
end;
end;
function card_id_sex(s:string):char;
var
x:integer;
begin
if not (length(s) in [15,18]) then
begin
showmessage(' ');
result:='x';
end;
if length(s)=15 then
begin
x:=strtoint(s[15]);
if x mod 2 =0 then
result:= 'f'
else
result:='m';
end;
if length(s)=18 then
begin
x:=strtoint(s[17]);
if x mod 2 =0 then
result:= 'f'
else
result:='m';
end;
end;
function card_id_sex(ID: string): boolean;
var
I: integer;
begin
I:= 17;
if Length(ID) = 15 then I := 15;
Result := StrToInt(ID[I]) mod 2 = 1;
end;
function card_id_birth(ID: string): TDate;
begin
if Length(ID) = 15 then
Result := StrtoDate(Format('19%s-%s-%s',[Copy(ID,7,2),Copy(ID,9,2),Copy(ID,11,2)]))
else
Result := StrtoDate(Format('%s-%s-%s',[Copy(ID,7,4),Copy(ID,11,2),Copy(ID,13,2)]));
end;
{==================以下是测试===========================}
procedure TForm1.Button1Click(Sender: TObject);
begin
if Card_id_sex('610118194910011238') then Showmessage('男') else Showmessage('女');
if Card_id_sex('610118491001124') then Showmessage('男') else Showmessage('女');
Showmessage(DateToStr(Card_id_birth('610118194910011238')));
Showmessage(DateToStr(Card_id_birth('610118491001123')));
end;
function card_id_sex(p_card_id :string):integer;
begin
If length(p_card_id) = 15 Then
I_card_num=Integer(Copy(p_card_id,(Length(p_card_id)-1,1))
Else
if len(p_card_id) = 18 Then
I_card_num = Integer(Copy(p_card_id,length(p_card_id)-1,1));
Else
messagebox("注意","身份证号码输入有误,请重试!",mb_ok+mb_iconinformation);
End;
If I_card_num = 0 Then
resule:='女'
Else
result:='男';// string(1)
End;
end;
function card_id_birth(s:string):Tdate;
var
i:integer;
str: string;
begin
if not (length(s) in [15,18]) then
begin
showmessage(' ');
result:=strtodate('1900-01-01');
end;
if length(s)=15 then
begin
str:='19'+copy(s,7,2)+'-'+copy(s,9,2)+'-'+copy(s,11,2);
result:=strtodate(str);
end;
if length(s)=18 then
begin
str:=copy(s,7,4)+'-'+copy(s,11,2)+'-'+copy(s,13,2);
result:=strtodate(str);
end;
end;
function card_id_sex(s:string):char;
var
x:integer;
begin
if not (length(s) in [15,18]) then
begin
showmessage(' ');
result:='x';
end;
if length(s)=15 then
begin
x:=strtoint(s[15]);
if x mod 2 =0 then
result:= 'f'
else
result:='m';
end;
if length(s)=18 then
begin
x:=strtoint(s[17]);
if x mod 2 =0 then
result:= 'f'
else
result:='m';
end;
end;
function card_id_birth(s:string):Tdate;
var
i:integer;
str: string;
begin
str:='';
if length(s)=15 then
begin
str:='19'+copy(s,7,2)+'-'+copy(s,9,2)+'-'+copy(s,11,2);
result:=strtodate(str);
end;
if length(s)=18 then
begin
str:=copy(s,7,4)+'-'+copy(s,11,2)+'-'+copy(s,13,2);
result:=strtodate(str);
end;
showmessage(str);
end;