Home >Web Front-end >JS Tutorial >js uses ID number to identify gender, age and birthday
Identifying gender, age and birthday based on ID number. There is currently such a demand. Then I will introduce how to use js to achieve it. Friends who are interested should not miss it
According to ID number JS code to identify gender, age and birthday:
The code is as follows:
function discriCard(){ //获取输入身份证号码 var UUserCard = ""; //获取出生日期 UUserCard. substr ing(6, 10) + "-" + UUserCard.sub string (10, 12) + "-" + UUserCard.substring(12, 14); //获取性别 if (parseInt(UUserCard.substr(16, 1)) % 2 == 1) { alert("男"); //是男则执行代码 ... } else { alert("女"); //是女则执行代码 ... } //获取年龄 var my Date = 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 }
The above is the detailed content of js uses ID number to identify gender, age and birthday. For more information, please follow other related articles on the PHP Chinese website!