附个牛逼的链接: https://www.cnblogs.com/cexm/p/7737538.html
一般密码的校验:
代码段:
computed: { resetRules () { var validateNewPass = (rule,value,callback) => { const reg = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[[email protected]$!%*#?&])[A-Za-z\[email protected]$!%*#?&]{6,18}$/ if (!reg.test(value)) { callback(new Error(‘密码应该为6-18位字母、数字、特殊字符组合‘)) } else { callback() } } var validatePass = (rule,callback) => { if (value !== this.resetword.newPwd) { callback(new Error(‘两次密码不一致‘)) } else { callback() } } return { newPwd: [ { required: true,message: ‘请输入新密码‘,trigger: ‘blur‘ },// { min: 6,max: 18,message: ‘密码应该为6-18位字母、数字、特殊字符组合‘,trigger: ‘blur‘ }, { validator: validateNewPass,trigger: ‘blur‘ } ],rePwd: [ { required: true,message: ‘请再次输入密码‘,{ validator: validatePass,trigger: ‘blur‘ } ] } } },
不能纯数字:
不能特殊字符,不能又有【】;
computed: { rules () { var validateSignature = (rule,callback) => { const reg = /^[\u4e00-\u9fa5A-Za-z0-9_]+$/ const reg2 = /^[0-9]+$/ if (!reg.test(value)) { callback(new Error(‘2-8个字,不能用特殊符号,不能纯数字‘)) } else if (reg2.test(value)) { callback(new Error(‘2-8个字,不能用特殊符号,不能纯数字‘)) } else { callback() } } var validateContent = (rule,callback) => { const reg = /[【】]/im if (reg.test(value)) { callback(new Error(‘5-300个字,不能有【】‘)) } else { callback() } } return { signature: [ { required: true,message: ‘请输入短信签名‘,{ validator: validateSignature,trigger: ‘blur‘ },{ min: 2,max: 8,message: ‘2-8个中英文,不能有特殊符,不能纯数字‘,content: [ { required: true,message: ‘请输入短信内容‘,{ validator: validateContent,{ min: 5,max: 300,message: ‘5-300个字,不能有【】‘,trigger: ‘blur‘ } ] } } },