Js simple implementation according to the id number to identify gender age and birthday
- 2020-03-30 00:40:38
- OfStack
JS code for identifying gender, age and birthday according to id number:
function discriCard(){
//Get input id number
var UUserCard = "";
//Get the date of birth
UUserCard.substring(6, 10) + "-" + UUserCard.substring(10, 12) + "-" + UUserCard.substring(12, 14);
//For gender
if (parseInt(UUserCard.substr(16, 1)) % 2 == 1) {
alert(" male ");
//The man executes the code...
} else {
alert(" female ");
//The woman executes the code...
}
//For age
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 is the age
}