15、18位身份证号码如何获取出生日期与性别?

Dision LI 2008-09-12 09:39:21
如题!
15位身份证号码:第7、8位为出生年份(两位数),第9、10位为出生月份,第11、12位代表出生日期,第15位代表性别,奇数为男,偶数为女。

18位身份证号码:第7、8、9、10位为出生年份(四位数),第11、第12位为出生月份,第13、14位代表出生日期,第17位代表性别,奇数为男,偶数为女。

或者帮忙把这翻译成D的

万分感谢!

  
'//所有的函数用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

...全文
6973 17 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
bnna2008 2011-03-18
  • 打赏
  • 举报
回复
好东西要看看的啦。
流梓 2008-09-12
  • 打赏
  • 举报
回复
来晚了,楼主以上的代码都贴出来,相信已经可以收工了!

俺贴段JS的吧。15位转18位
function idcard_verify_number(sfzh)
{
var str1 =new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2");
var int1 =new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1);
var ll_sum=0;
var i;
var ls_check;
zjhm = sfzh.substring(0, 6) + "19" + sfzh.substring(6);
for (i=0;i<=16;i++){
ll_sum=ll_sum+(parseFloat(sfzh.substr(i,1)))*int1 [i];
}
ll_sum = ll_sum % 11;
int1 =int1 + strJiaoYan[ll_sum];
return sfzh;
}
mastersky 2008-09-12
  • 打赏
  • 举报
回复

//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;

柯本 2008-09-12
  • 打赏
  • 举报
回复
我的功能:
1.检查身份证是否合法(非法返回空)
2.得到出身年月日及性别
3.将15位升级到18位
Dision LI 2008-09-12
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 JeffChung 的回复:]
主要是copy.

楼上大家都很有热情啊
[/Quote]

呵呵!是啊!我自己搜索了半天只找到段VB的代码

非常感谢!!


测试中...
柯本 2008-09-12
  • 打赏
  • 举报
回复
来晚了,不过我还是把我用的给LZ参考一下:

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;
lihuasoft 2008-09-12
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 JeffChung 的回复:]
主要是copy.

楼上大家都很有热情啊
[/Quote]

有分就有激情
5楼俺的代码还算简练吧
JeffChung 2008-09-12
  • 打赏
  • 举报
回复
主要是copy.

楼上大家都很有热情啊
Dision LI 2008-09-12
  • 打赏
  • 举报
回复
多谢以上各位大侠
呵呵
自己也在按那VB的改着代码
测试完后再揭贴!
lyguo 2008-09-12
  • 打赏
  • 举报
回复
15位的号码为:

aa bb cc yymmdd nnn
aa: 省份编码
bb: 省地区编码,表示省级市或省级县(直辖市则01表示市区,02以后表示直辖市辖区内的郊县)
cc: 地级县(市)编码,表示地级市(直辖市则表示行政区编号,比如上海市的卢湾区,虹口区等)

yymmdd: 出生年月日,其中yy用年份的后两位表示

nnn: 同一地区出生年月日相同的人的序号
需要注意的是该序号以户主为准,子女依照户主序号确定
奇数=男,偶数=女,且 女=男+1
比如:上海地区虹口区有一户人家,户主的编号是:
310109520801037
^^^
则子: 310109770611037
^^^
女: 310109790214038
^^^


新的18位为:
aa bb cc yyyymmdd nnn r
其中就是将原有的2位年份改为4位,最后一位为校验位,而且不一定是奇男偶女
所以新的18位号码判断男女是看最后第2位。
fangsp 2008-09-12
  • 打赏
  • 举报
回复
再顶一个
fangsp 2008-09-12
  • 打赏
  • 举报
回复
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;
lihuasoft 2008-09-12
  • 打赏
  • 举报
回复

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;
shuihan20e 2008-09-12
  • 打赏
  • 举报
回复
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;


调试下吧,我没调试

yuqianyi1974 2008-09-12
  • 打赏
  • 举报
回复

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;
yuqianyi1974 2008-09-12
  • 打赏
  • 举报
回复
计算生日

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;
Dision LI 2008-09-12
  • 打赏
  • 举报
回复
Edit1上写入身份证号码,焦点离开的时候,根据身份证号码正确地显示出生日期到DateTimePicker1 和 性别到 ComboBox1中.

16,747

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧