function discriCard(idCard){ 
    var user = {};
    //获取输入身份证号码 idCard

    //获取出生日期 
    idCard.substring(6, 10) + "-" + idCard.substring(10, 12) + "-" + idCard.substring(12, 14); 
    //获取性别 
    if (parseInt(idCard.substr(16, 1)) % 2 == 1) {
        //是男则执行代码 ...  
        user.sex = 2;
    } else { 
        //是女则执行代码 ... 
        user.sex = 1;
    } 
    //获取年龄 
    var myDate = new Date(); 
    var month = myDate.getMonth() + 1; 
    var day = myDate.getDate(); 
    var age = myDate.getFullYear() - idCard.substring(6, 10) - 1; 
    if (idCard.substring(10, 12) < month || idCard.substring(10, 12) == month && idCard.substring(12, 14) <= day) { 
        age++; 
    }
    //年龄 age 
    user.age = age;
    var birthday = "";  
        if(idCard != null && idCard != ""){  
            if(idCard.length == 15){  
                birthday = "19"+idCard.substr(6,6);  
            } else if(idCard.length == 18){  
                birthday = idCard.substr(6,8);  
            }  
          
            birthday = birthday.replace(/(.{4})(.{2})/,"$1-$2-");  
        }  
    //出生日期
    user.birthday = birthday;
    return user;
}

 

 posted on 2016-07-20 10:48  顺文章  阅读(480)  评论(0编辑  收藏  举报