data() {
//验证手机号的正则表达式
let reg =
/^(((13[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(17[3-8]{1})|(18[0-9]{1})|(19[0-9]{1})|(14[5-7]{1}))+\d{8})$/;
//验证方法
let validatorPhone = function (tel, value, callback) {
if (value === "") {
callback(new Error("手机号不能为空"));
} else if (!reg.test(value)) {
callback(new Error("手机号格式错误"));
} else {
callback();
}
}
return {
dialogFormVisible: false,
form: {
tel: "",
desc: "",
},
rules: {
desc: [{ required: true, message: "必填", trigger: "blur" }],
tel: [
{
validator: validatorPhone,
required: true,
trigger: "blur",
},
],
}
}
},
methods: {
onSubmit(form) {
this.$refs[form].validate((valid) => {
if (valid) {
console.log(this.form.tel);
console.log(this.form.desc);
// alert("submit!");
} else {
console.log("error submit!!");
return false;
}
});
},
}
09-12
883