element 表单验证的几种方式

一、

规则里:

pesonRules: {
        phone: [
          { required: true, message: "手机号不能为空", trigger: "blur" },
          { validator: checkPhone, trigger: "blur" }
        ]
}

data里声明:

data() {
    var checkPhone = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("手机号不能为空"));
      } else {
        const reg = /^1[3|4|5|7|8][0-9]\d{8}$/;
        if (reg.test(value)) {
          callback();
        } else {
          return callback(new Error("请输入正确的手机号"));
        }
      }
    };
    var Rate = (rule, value, callback) => {
      const reg = /^\d*(?:\.\d{0,4})?$/;
      if (reg.test(value)) {
        callback();
      } else {
        this.submitData.contributionRate = "";
        return callback(new Error("请输入4位小数以内的数字"));
      }
    };
    var checkB = (rule, value, callback) => {
      let reg = /^([1-9]{1})(\d{14}|\d{18})$/;
      if (reg.test(value)) {
        callback();
      } else {
        return callback(new Error("请输入正确的账号"));
      }
    };
    var checkA = (rule, value, callback) => {
      let reg = /^[0-9]*[1-9][0-9]*$/;
      if (reg.test(value)) {
        callback();
      } else {
        return callback(new Error("请输入正整数"));
      }
    };
}

你可能感兴趣的:(vue.js,css3,elementui)