码迷,mamicode.com
首页 > 其他好文 > 详细

根据身份证自动获取年龄/出生日期

时间:2019-12-10 16:52:08      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:item   sdi   led   highlight   size   截取   card   let   出生日期   

<el-form-item label="证件号" prop="idCard">
       <el-input
            v-model="form.idCard"
             size="small"
             :disabled="isDisabled"
              style="width:90%;"
              @blur="getName(form.idCard)"
         ></el-input>
</el-form-item>

methods: {
      getName(iden) {
      let val = iden.length;
      let sex = null;
      let birth = null;
      let myDate = new Date();
      let month = myDate.getMonth() + 1;
      let day = myDate.getDate();
      let age = 0;
   
    //判断身份证位数为18位时去截取时间日期 if (val === 18) { age = myDate.getFullYear() - iden.substring(6, 10) - 1; sex = iden.substring(16, 17); birth = iden.substring(6, 10) + "-" + iden.substring(10, 12) + "-" + iden.substring(12, 14); if ( iden.substring(10, 12) < month || (iden.substring(10, 12) == month && iden.substring(12, 14) <= day) ) age++; }
    
    //判断身份证位数为15位时去截取时间日期 if (val === 15) { age = myDate.getFullYear() - iden.substring(6, 8) - 1901; sex = iden.substring(13, 14); birth = "19" + iden.substring(6, 8) + "-" + iden.substring(8, 10) + "-" + iden.substring(10, 12); if ( iden.substring(8, 10) < month || (iden.substring(8, 10) == month && iden.substring(10, 12) <= day) ) age++; } this.form.age = age; this.form.dob = birth; // this.getDataInfo(); } }

  

根据身份证自动获取年龄/出生日期

标签:item   sdi   led   highlight   size   截取   card   let   出生日期   

原文地址:https://www.cnblogs.com/swmin/p/12017342.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!