邮箱验证:
const regemail = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.]){1,2}[A-Za-z\d]{2,5}$/g if(!regemail.test(value)){ return cb(new Error('请输入正确的手机号')) }
手机号验证:
const regemail = /^1[3456789]\d{9}$/
纳税人识别号:
const regEmail = /^[A-Z0-9]{15}$|^[A-Z0-9]{17}$|^[A-Z0-9]{18}$|^[A-Z0-9]{20}$/
密码验证
this.$refs.changePsw.setRules({ newPsw: { rules: [ { required: true, errorMessage: '密码长度不得小于8位,必须包含大写字母、小写字母、数字、特殊符号中3种或以上组合,且不可输入3位连续字符(含键盘排布连续)或重复字符。' }, { validateFunction: function (rule, value, data, callback) { let pass = value; console.log(that.checkPass(pass),'that.checkPass(pass)') if (that.checkPass(pass) < 2) { callback('密码长度不得小于8位,必须包含大写字母、小写字母、数字、特殊符号中3种或以上组合,且不可输入3位连续字符(含键盘排布连续)或重复字符。') } return true; } }] }, repeatPsw: { rules: [ { required: true, errorMessage: '必填信息' }, { validateFunction: function (rule, value, data, callback) { if (value !== that.changePsw.newPsw) { callback('两次输入的密码不一致') } return true; } } ] } },)
checkPass(pass) { var checkCount = 0; var regx = /[a-z]/; if (regx.test(pass)) { checkCount += 1; } regx = /[A-Z]/; if (regx.test(pass)) { checkCount += 1; } regx = /\d/; if (regx.test(pass)) { checkCount += 1; } regx = /[^a-zA-Z0-9]/ if (regx.test(pass)) { checkCount += 1; } if(pass.length >= 8){ checkCount += 1; } if (checkCount < 4) { return 0; } const regxs = [ 'qwertyuiop[]', 'qwertyuiop{}|', 'asdfghjkl;', 'asdfghjkl:"', 'zxcvbnm,./', 'zxcvbnm<>?', '1234567890-=', '!@#$%^&*()_+', '!@#$%^&*()_+', '1qaz', '2wsx', '3edc', '4rfv', '5tgb', '6yhn', '7ujm', '8ik,', '9ol.', '0p;/', '!qaz', '@wsx', '#edc', '$rfv', '%tgb', '…yhn', '^yhn', '&ujm', '*ik,', '(ol.', ')p;/', '(ol.', ')p;/', '741', '852', '963', ]; for (let i = 0, length = regxs.length; i < length; i++) { let str = regxs[i]; regxs.push([...str].reverse().join('')); } for (let i = 0; i < regxs.length; i++) { let str = regxs[i]; for (let j = 0; j < str.length - 2; j++) { let strj = str.substring(j, j + 3); if (pass.toLowerCase().includes(strj)) { return 0; } } } if (!this.hasConsecutiveOrder(pass.toLowerCase())) { return 0; } return 2; }, // 判断给定字符串中是否存在连续的三个字符(字母或数字) hasConsecutiveOrder(str) { for (let i = 1; i < str.length - 1; i++) { if (str.charAt(i) == str.charAt(i - 1) && str.charAt(i) == str.charAt(i + 1)) { return false; } } return true; // 循环结束后,返回 true,表示校验通过 },