通过身份证号得到出生日期和性别的js代码

2019-12-25,,,,

//身份证校验 与得到生日代码
复制代码 代码如下:
<script language="javascript">
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;
}
}

您可能感兴趣的文章:

  • JavaScript正则表达式验证身份证号码是否合法(两种方法)
  • js实现二代身份证号码验证详解
  • javascript验证身份证号
  • javascript或asp实现的判断身份证号码是否正确两种验证方法
  • Node.js通过身份证号验证年龄、出生日期性别方法示例

《通过身份证号得到出生日期和性别的js代码.doc》

下载本文的Word格式文档,以方便收藏与打印。