ID card can identify a person's information, the following describes how to use JS through the ID card number to obtain the age and sex of the parties.
<script>
function Idcard (uusercard,num) {
if (num==1) {
//Get Birth date
birth=uusercard.substring (6 + "-" + uusercard.substring (a) + "-" + uusercard.substring (a);
return birth;
}
if (num==2) {
//Get Sex
if (parseint (UUSERCARD.SUBSTR (1))% 2 = 1) {//
male return
"male";
} else {
//woman return
"female";
}
if (num==3) {
//Get age
var mydate = new Date ();
var month = Mydate.getmonth () + 1;
var day = Mydate.getdate ();
var age = Mydate.getfullyear ()-uusercard.substring (6, ten)-1;
if (uusercard.substring < month | | Uusercard.substring = = Month && uusercard.substring (a) <= day) {
age++;
}
return age;
}
}
Alert (Idcard (' 142223198503226111 ', 3));
</script>
Here's a piece of code for you to get people's age and sex through their ID numbers.
The code example is as follows:
The above code implements our requirements, enter the ID number in the text box, and then click the button to pop up the age and sex.