验证邮箱,手机号
<el-form ref="form" :model="form" :rules="formRules" label-width="80px">
<el-form-item label="邮箱" class="email" prop="email">
<el-input v-model="form.email"></el-input>
</el-form-item>
<el-form-item label="手机号" class="phone" prop="phone">
<el-input v-model="form.phone"></el-input>
</el-form-item>
</el-form>
data() {
var checkPhone = (rule, value, callback) => {
const reg = /^1([38][0-9]|4[014-9]|[59][0-35-9]|6[2567]|7[0-8])\d{8}$/
setTimeout(() => {
if (reg.test(value)) {
callback()
} else {
callback(new Error('请请正确输入手机号码!'))
}
}, 100)
}
var checkEmail = (rule, value, callback) => {//邮箱校验
const mailReg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/
if (!value) {
return callback(new Error('邮箱不能为空!'))
}
setTimeout(() => {
if (mailReg.test(value)) {
callback()
} else {
callback(new Error('请输入正确的邮箱格式!'))
}
}, 100)
}
return {
Rules: {
email: [{ required: true, trigger: 'blur', validator: checkEmail }],
phone: [{required: true, trigger: 'blur', validator: checkPhone }],
}
}
},