js-ID card to identify gender and date of birth

***certNo: ID number
Return value: xxxx-xx-xx/male


  function(certNo) {
    
    
    var _len = certNo.length;//获取身份证的长度
    let brith="";//出生日期 xxxx-xx-xx
    let sex = "";//性别
	//处理18位的身份证号码从号码中得到生日和性别代码
    if (_len == 18){
    
    
        brith=certNo.substr(6, 4) + "-" + certNo.substr(10, 2) + "-" + certNo.substr(12, 2),
        sex:parseInt(certNo.substr(16,1)) % 2==1?"男":"女"
    }
    if (_len == 15) {
    
    
        brith="19" + certNo.substr(6, 2) + "-" + certNo.substr(8, 2) + "-" + certNo.substr(10, 2),
        sex=arseInt(certNo.substr(14,1)) % 2==1?"男":"女"
    }
    return brith +"/"+x;
  },

Guess you like

Origin blog.csdn.net/qq_42944436/article/details/112265631