js根据身份证 判断性别 出生、年龄、出生年月日
function discriCard() {
//获取输入身份证号码
var UUserCard = "";
//获取出生日期
UUserCard.substring(6, 10) + "-" + UUserCard.substring(10, 12) + "-" + UUserCard.substring(12, 14);
//获取性别
if (parseInt(UUserCard.substr(16, 1)) % 2 == 1) {
alert("男");
//是男则执行代码 ...
} else {
alert("女");
//是女则执行代码 ...
}
//获取年龄
var myDate = new Date();
var month = myDate.getMonth() + 1;
var day = myDate.getDate();
var age = myDate.getFullYear() - UUserCard.substring(6, 10) - 1;
if (UUserCard.substring(10, 12) < month || UUserCard.substring(10, 12) == month && UUserCard.substring(12, 14) <= day) {
age++;
}
alert(age);
//年龄 age
}