如何根据身份证判断出生日期和性别啊?

wlwwd 2008-12-07 08:22:49
身份证:文本框
出生日期:文本框
性别:下拉菜单

当我输入身份证号码,下面的出生日期和性别能自动显示出来

谢谢!
...全文
918 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wlwwd 2008-12-08
  • 打赏
  • 举报
回复
真的很谢谢你!
追加100分
:)
varlj 2008-12-07
  • 打赏
  • 举报
回复

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
身份证:<input type="text" id="sfz" onblur="fun()"/>
生日:<input type="text" id="sr" />
性别:
<select id="sex">
<option>男</option>
<option>女</option>
</select>
<script type="text/javascript">
function fun()
{
var sfz = document.getElementById("sfz");
var sr = document.getElementById("sr");
var sex = document.getElementById("sex");
if(sfz.value.length!=18 && sfz.value.length!=15)
{
alert("生日错误");
return;
}
var birthday;
var sexflag;
if(sfz.value.length==18)
{
birthday = sfz.value.substring(6,14);
sexflag = sfz.value.substring(14,17).replace(/^0*/,"");
}
else
{
birthday = "19"+sfz.value.substring(6,12);
sexflag = sfz.value.charAt(14);
}

sr.value = birthday.replace(/(\d{4})(\d{2})(\d{2})/,"$1年$2月$3日");
var s = sexflag.replace(/^0*/,"");
if( parseInt(s,10)%2==0 )
sex.selectedIndex = 1;
else
sex.selectedIndex = 0;
}
</script>
</body>
</html>

varlj 2008-12-07
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wlwwd 的回复:]
非常感谢varlj

大哥,身份证有15位和18位的,你能不能分开给我判断下啊

我追加50分给你
[/Quote]
被你引诱成功了……
wlwwd 2008-12-07
  • 打赏
  • 举报
回复
非常感谢varlj

大哥,身份证有15位和18位的,你能不能分开给我判断下啊

我追加50分给你
wuyq11 2008-12-07
  • 打赏
  • 举报
回复
参考
http://topic.csdn.net/u/20081111/11/4d1e42a8-8749-40ec-a215-bea9229b7374.html?56860247
wuyq11 2008-12-07
  • 打赏
  • 举报
回复
function showBirthday(val)
{
var birthdayValue;
if(15==val.length)
{ //15位身份证号码
birthdayValue = val.charAt(6)+val.charAt(7);
if(parseInt(birthdayValue)<10)
{
birthdayValue = '20'+birthdayValue;
}
else
{
birthdayValue = '19'+birthdayValue;
}
birthdayValue=birthdayValue+'-'+val.charAt(8)+val.charAt(9)+'-'+val.charAt(10)+val.charAt(11);
if(parseInt(val.charAt(14)/2)*2!=val.charAt(14))
document.all.sex.value='男';
else
document.all.sex.value='女';
document.all.birthday.value=birthdayValue;
}
if(18==val.length)
{ //18位身份证号码
birthdayValue=val.charAt(6)+val.charAt(7)+val.charAt(8)+val.charAt(9)+'-'+val.charAt(10)+val.charAt(11)

+'-'+val.charAt(12)+val.charAt(13);
if(parseInt(val.charAt(16)/2)*2!=val.charAt(16))
document.all.sex.value='男';
else
document.all.sex.value='女';
if(val.charAt(17)!=IDCard(val))
{
document.all.idCard.style.backgroundColor='#ffc8c8';
}
else
{
document.all.idCard.style.backgroundColor='white';
}
document.all.birthday.value=birthdayValue;
}
}

// 18位身份证号最后一位校验
function IDCard(Num)
{
if (Num.length!=18)
return false;
var x=0;
var y='';

for(i=18;i>=2;i--)
x = x + (square(2,(i-1))%11)*parseInt(Num.charAt(19-i-1));
x%=11;
y=12-x;
if (x==0)
y='1';
if (x==1)
y='0';
if (x==2)
y='X';
return y;
}

// 求得x的y次方
function square(x,y)
{
var i=1;
for (j=1;j<=y;j++)
i*=x;
return i;
}
</script>
varlj 2008-12-07
  • 打赏
  • 举报
回复
试着自己写一下,就会了


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
身份证:<input type="text" id="sfz" onblur="fun()"/>
生日:<input type="text" id="sr" />
性别:
<select id="sex">
<option>男</option>
<option>女</option>
</select>
<script type="text/javascript">
function fun()
{
var sfz = document.getElementById("sfz");
var sr = document.getElementById("sr");
var sex = document.getElementById("sex");
if(sfz.value.length!=18)
{
alert("生日错误");
return;
}

sr.value = sfz.value.substring(6,14).replace(/(\d{4})(\d{2})(\d{2})/,"$1年$2月$3日");
var s = sfz.value.substring(14,17).replace(/^0*/,"");
if( parseInt(s,10)%2==0 )
sex.selectedIndex = 1;
else
sex.selectedIndex = 0;
}
</script>
</body>
</html>

wlwwd 2008-12-07
  • 打赏
  • 举报
回复
代码我不会写
谁帮帮我
varlj 2008-12-07
  • 打赏
  • 举报
回复
330488198812110039

对于18位身份证来说,检查上面红色的数字,如果是奇数,表示男性,否则女性

87,914

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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