日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

input框錄入身份證自動填寫性別年齡

作者:曉魚姑娘 更新時間: 2023-10-16 編程語言

1.data

      //基礎(chǔ)規(guī)范
      rules: {
        idcard: [
          { required: true, message: "身份證號不能為空", trigger: "blur" },
          { validator: this.validID, trigger: ["blur", "change"] }
        ]
      },

2.1 methods

    /* 身份證驗(yàn)證 */
    async validID(rule, value, callback) {
      // 身份證號碼為15位或者18位,15位時全為數(shù)字,18位前17位為數(shù)字,最后一位是校驗(yàn)位,可能為數(shù)字或字符X
      let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
      if (reg.test(value)) {
        let info = await this.go(value.length);
        console.log(info);
        await this.setInfo(info);
      } else {
        this.gender = "";
        this.birthday = "";
        callback(new Error("身份證號碼不正確"));
      }
    },

2.2 methods

    /* 設(shè)置屬性 */
    setInfo(info) {
      var that = this;
      that.birthday = info[1];
      that.gender = info[0];
    },

2.3 methods

    // 實(shí)現(xiàn)自動生成生日,性別,年齡
    go(val) {
      let iden = this.person.idcard;
      let sex = null;
      let birth = null;
      let myDate = new Date();
      let month = myDate.getMonth() + 1;
      let day = myDate.getDate();
      let age = 0;
      if (val === 18) {
        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++;
      }
      if (val === 15) {
        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++;
      }

      if (sex % 2 === 0) sex = "0";
      else sex = "1";
      let info = [];
      info.push(sex, birth);
      return info;
    },

原文鏈接:https://blog.csdn.net/weixin_37201927/article/details/100578116

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新