Home > Web Front-end > JS Tutorial > body text

js uses ID number to identify gender, age and birthday

怪我咯
Release: 2017-06-29 10:26:55
Original
2151 people have browsed it

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 
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!