如何在Element 使用正则表达式校验
Template
<el-input v-model.number="form.phone" placeholder="请输入手机号" />
<el-input v-model="form.sfz" placeholder="请填写身份证"></el-input>
表单校验
rules: {
phone :[
{
type: 'number',
required: true,
message: '请输入手机号',
trigger: 'blur'
},
{
pattern: /^0{0,1}(13[0-9]|15[7-9]|153|156|18[7-9])[0-9]{8}$/,
message: '手机号格式不对',
trigger: 'blur'
}
],
sfz :[
{ required: true, message: '请填写证件号码', trigger: 'blur' },
{
pattern: /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/,
message: '证件号码格式有误!',
trigger: 'blur'
}
],
},