正则验证合集

邮箱验证:

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,表示校验通过
},

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值