参考:http://www.tuicool.com/articles/J7r2ien

方式一:

 $scope.GetAgeAndSexByIDNum = function (IdCardNO)
{
// 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X
var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
if (reg.test(IdCardNO) === false)
{
alert("身份证号输入不合法");
return false;
}
var date = new Date();
var yearfull = date.getFullYear();
if (IdCardNO.length == 18)//18位身份证号处理
{
var birthyear = IdCardNO.substring(6, 10);
var month = IdCardNO.substring(10, 12);
var day = IdCardNO.substring(12, 14);
var age = yearfull - birthyear;
var sexValue = IdCardNO.substring(16, 17);
var sex = (sexName % 2 == 0 ? "女" : "男");
if (sex.toString() == "女")
sexValue = "2";
if (sex.toString() == "男")
sexValue = "1";
else sexValue = "3";
$scope.applyForm.Age = age; document.getElementById("sex").value = sexValue;
$scope.patient.sex = sex;
}
if (IdCardNO.length == 15)//15位身份证号处理
{
var birthDay = "";
birthDay = IdCardNO.substring(6, 12);
birthDay = "19" + birthDay;
birthDay = birthDay.substring(0, 4);// + "-" + birthDay.substring(4, 6) + "-" + birthDay.substring(6)
var age = yearfull - birthDay;//年龄
var sex = parseInt(birthDay.substring(14, 1), 10) % 2 ? "男" : "女";//性别
var sexValue = "";
if (sex.toString() == "女")
sexValue = "2";
if (sex.toString() == "男")
sexValue = "1";
else sexValue = "3";
$scope.applyForm.Age = age;
document.getElementById("sex").value = sexValue;
$scope.patient.sex = sex;
}
};
方式二:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="jquery.min.js"></script>
</head>
<body>
<input type="tel" id="js_Idcard">
<span id="js_birthday"></span>
<script>
$(function(){
function GetBirthdatByIdNo(iIdNo){
var tmpStr = "";
var birthday = $("#js_birthday"); iIdNo = $.trim(iIdNo); if(iIdNo.length == ){
tmpStr = iIdNo.substring(, );
tmpStr = "" + tmpStr;
tmpStr = tmpStr.substring(, ) + "-" + tmpStr.substring(, ) + "-" + tmpStr.substring();
sexStr = parseInt(iIdNo.substring(, ),) % ? "男" : "女";
birthday.text(sexStr + tmpStr);
}else{
tmpStr = iIdNo.substring(, );
tmpStr = tmpStr.substring(, ) + "-" + tmpStr.substring(, ) + "-" + tmpStr.substring();
sexStr = parseInt(iIdNo.substring(, ),) % ? "男" : "女";
birthday.text(sexStr + tmpStr);
}
} $("#js_Idcard").blur(function(){
GetBirthdatByIdNo($(this).val());
});
});
</script>
</body>
</html> 方式三: <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="jquery.min.js"></script>
</head> <body>
<input type="tel" id="js_Idcard">
<span id="js_birthday"></span>
<script>
$(function(){
function go(){
var id = $("#js_Idcard").val();
var last = id[id.length - ]; if(last % != ){
$("#js_birthday").text("男");
}else{
$("#js_birthday").text("女");
}
} $("#js_Idcard").blur(function(){
go();
});
});
</script>
</body>
</html>

Js 根据身份证号获取年龄-性别的更多相关文章

  1. js 根据身份证号获取性别,年龄,等

    $(function(){        $("#corpOwnerIdno").blur(function(){          //获取输入身份证号码             ...

  2. JS通过身份证号获取生日、年龄、性别

    <script> function IdCard(UUserCard,num){ if(num==1){ //获取出生日期 birth=UUserCard.substring(6, 10) ...

  3. js脚本根据身份证号获取性别、年龄、家庭地址、生日

    做项目测试时需要根据身份证号获取其信息,也不想调接口,就自己在本地通过收集资料整合了一个

  4. JavaScript 通过身份证号获取出生日期、年龄、性别 、籍贯

    JavaScript 通过身份证号获取出生日期.年龄.性别 .籍贯(很全) 效果图: 示例代码: //由于没有写外部JS,所以代码比较长!!! <!DOCTYPE html PUBLIC &qu ...

  5. IOS 根据身份证号码获取 年龄 生日 性别

    /** 从身份证上获取年龄 18位身份证 */ -(NSString *)getIdentityCardAge:(NSString *)numberStr { NSDateFormatter *for ...

  6. js验证身份证号,超准确

    js验证身份证号,超准确 看程序前先来了解下身份证号的构成:身份证号分为两种,旧的为15位,新的为18位.身份证15位编码规则:dddddd yymmdd xx p    其中 dddddd:地区码  ...

  7. SQL语句通过身份证号计算年龄

    SQL语句通过身份证号计算年龄 1.截取身份证号上的出生日期 身份证一般为18位数和15位数 18位数身份证的第7-10位数是出生年份,第11-14位数是出生月日,所以18位身份证的年龄计算如下 su ...

  8. js从身份证号中获取出生日期和性别

    今天,在做移动端的项目中,按照设计稿的要求,是可以让用户自己输入出生日期的,我还很认真的用了刚刚知道的html5表单的日期类型,本想着终于不用日期插件就可以实现用户选择自己的出生日期了,可结果老大说, ...

  9. python 根据生日计算年龄 sqlalchemy根据身份证号计算生日 性别

    import datetime '): birth_d = datetime.datetime.strptime(birth_s, "%Y%m%d") today_d = date ...

随机推荐

  1. Jmeter增加压力机方法

    windows: 需要别人的机器也安装jmeter 在别人的机器上运行jmeter-server.bat 修改jmeter.properties文件,查找remote_hosts 原始:remote_ ...

  2. JAVA(3)

    接口注意事项: 1.接口不能被实例化 2.接口中所有的方法都不能有主体  (不能有{ }) 3.一个类可以实现多个接口 4.接口中可以有变量<但变量不能用private和protected修饰& ...

  3. 关于Ciarlet的泛函的一道homework的一个想法

    [转载请注明出处]http://www.cnblogs.com/mashiqi 2016/11/21 有一道题是证明$(\mathbb{R}^n,\|\cdot\|_p)$当$p : 1< p ...

  4. CLR via C# 3rd - 01 - The CLR's Execution Model

    1. Assemly       A managed module is a standard 32-bit Microsoft Windoes portable executable (PE32) ...

  5. iOS后台挂起程序 当程序到后台后,继续完成Long-Running Task 任务

    我们知道,到我们程序从前台退到后台(安home)键后,将执行程序的委托方法. // 当应用程序掉到后台时,执行该方法 - (void)applicationDidEnterBackground:(UI ...

  6. MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 的解决办法和原因

    这两天下载了MySQL5.7.11进行安装,发现到了初次使用输入密码的时候,不管怎样都进不去,即使按照网上说的在mysqld 下面添加skip-grant-tables也是不行,后来研究了两天,终于找 ...

  7. 转载《 LayoutInflater 的inflate函数用法详解》

    很多人在网上问LayoutInflater类的用法,以及inflate()方法参数的含义,现解释如下: inflate()的作用就是将一个用xml定义的布局文件查找出来,注意与findViewById ...

  8. EXTJS4.2中neptune主题的使用

    原文地址:http://blog.csdn.net/xieguojun2013/article/details/8880519 最近在在sencha.com官网了解到EXTJS的最新版本里增加了新的主 ...

  9. java程序员烂大街为何还不便宜?

    最近跟一朋友聊天,他是做c#开发的.他答应了老板带领一帮java工程师开发网站.披星戴月终于搞定,现在已经盈利.但是他公司的那帮搞c#的同事不淡定了. 在招聘java程序员的时候2年有开15k的.5年 ...

  10. A log about Reading the memroy of Other Process in C++/WIN API--ReadProcessMemory()

    Memory, is a complex module in Programing, especially on Windows. This time, I use cpp with win wind ...