一、手机号验证
html部分:
data中表单验证:
addRules: {phoneNumber: [{validator: this.checkPhone,required: true,trigger: 'blur' }]},
js:
methods:{checkPhone(rule, value, callback) {if (!value) {callback(new Error('请输入联系人手机号'))} else {const reg = /^1[3|4|5|7|8|9][0-9]\d{8}$/; //手机号正则表达式//const reg = /^([0-9]{3,4}-)?[0-9]{7,8}$/; //座机号正则表达式//const reg =/^([1-9]{1})(\d{14}|\d{18})$/; //通用银行账号正则表达式//const reg = /^[1-9][0-9]{5}$/; //邮编正则表达式//const reg = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;//传真正则表达式console.log(reg.test(value))if (reg.test(value)) {callback()} else {return callback(new Error('请输入正确的手机号'))}}},}
参考:/weixin_44455452/article/details/100019703
二、电子邮箱验证
<el-form-itemlabel="电子邮件:"prop="email":rules="[{required: false, message: '请输入邮箱地址', trigger: 'blur' },{type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }]"><el-input v-model="logisticsCompanyInformation.email"></el-input></el-form-item>