How to use JS to obtain the party's birthday, age, gender _javascript skills through the ID card number

Source: Internet
Author: User
Tags getdate

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:

<! DOCTYPE html>  

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.