Element UI 自定义正则表达式验证方法

今天小编就为大家分享一篇Element UI 自定义正则表达式验证方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

如下所示:

 //指定数据中心的验证表单valiForm,验证规则rules   
 //add('valiForm')方法要传验证表单名 确 定
 data () { let nameRule1 = (rule, value, callback) => { let regExp = //; if (regExp.test(value) === false) { callback(new Error('不通过正则')); } else { callback(); } }; return { valiForm: { name: '' }, rules: { name: [ { required: true, message: '请输入名称', trigger: 'blur' }, { min: 5, max: 10, message: '长度在 5 到 10 个字符', trigger: 'blur' }, { validator: nameRule1, trigger: 'blur' } ] } }; },
 methods:{ add(formName) { this.$refs[formName].validate((valid) => { if (valid) { //通过验证执行 } else { //验证失败执行 console.log('error submit!!'); return false; } }); } }

以上就是Element UI 自定义正则表达式验证方法的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Vue.js 教程