-
patter 属性规定用于验证输入字段的模式。模式指的是正则表达式。
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
<el-form-item label="手机" prop="phone ">
<el-input type="phone " v-model="ruleForm.phone " autocomplete="off"></el-input>
</el-form-item>
</el-form>
export default {
data(){
return {
ruleForm:{ phone : ' ' }
}
}
rules: {
phone = [
{ pattern: /^1[3-9](\d{9})$/, message: '请输入正确的手机号', trigger: 'change' },
{ max: 11, message: '请输入11位手机号', trigger: 'change' }
]
}
}
-
注意: v-model="ruleForm.phone
和 prop="phone
" 值要相同