自定义规则

This commit is contained in:
xing 2020-06-18 16:41:11 +08:00
parent d489ea8115
commit 12ffc656a6

View File

@ -70,7 +70,7 @@
<el-input v-model="addForm.email"></el-input>
</el-form-item>
<el-form-item label="手机" prop="mobile">
<el-input v-model="addForm.email"></el-input>
<el-input v-model="addForm.mobile"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
@ -92,6 +92,17 @@
<script>
export default {
data () {
const checkemail = (rule, value, callback) => {
const reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+\.([a-zA-Z_-])+/
if (reg.test(value)) {
return callback()
}
callback(new Error('邮箱地址不合法'))
}
const checkMobile = (rule, value, callback) => {
const reg = /^1\d{10}$/
reg.test(value) ? callback() : callback(new Error('手机号不合法'))
}
return {
dialogVisible: false,
addForm: {
@ -111,11 +122,13 @@ export default {
],
email: [
{ required: true, message: '请输入邮箱', trigger: 'blur' },
{ min: 3, max: 10, message: '长度在3到10之间', trigger: 'blur' }
{ min: 3, message: '长度错误', trigger: 'blur' },
{ validator: checkemail, trigger: 'blur' }
],
mobile: [
{ required: true, message: '请输入手机号', trigger: 'blur' },
{ min: 3, max: 10, message: '长度在3到10之间', trigger: 'blur' }
{ min: 11, max: 11, message: '长度为11位', trigger: 'blur' },
{ validator: checkMobile, trigger: 'blur' }
]
},
queryInfo: {