Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bee0060/8ca6ab5aba57ee3cb63f to your computer and use it in GitHub Desktop.
Save bee0060/8ca6ab5aba57ee3cb63f to your computer and use it in GitHub Desktop.
根据input输入情况,检验密码的强度,规则如下:
1. 纯数字,纯字母为:弱。
2. 数字与字母组合为:中。
3. 数字,字母,特殊字符@#$%^&*_+[]{}组合为:强。
4. 以上长度必为8位以上。
PS:
1. 回复时注意加上下面这句话,才会有语法高亮或格式缩进。
```javascript
// you code
```
2. 粘贴代码时请使用shift+tab,缩进前面的空白。
@bee0060
Copy link
Author

bee0060 commented May 30, 2014

function check(input)
{
    var regOnlyNumber = /^[0-9]{8,}$/,
        regOnlyNumberAndLetter = /(?!^[0-9]+$)(?!^[a-zA-Z]+$)^[0-9a-zA-Z]{8,}$/,
        regIncludeNumberAndLetter = /[0-9a-zA-Z]+/,
        regIncludeChars = /[@#$%^&*_+\[\]\{\}]+/,

        level = 0; // 1: simple; 2: normal; 3: high


    regOnlyNumber.test(input) && level = 1;
    regOnlyNumberAndLetter.test(input) && level = 2;
    regIncludeNumberAndLetter.test(input) &&
      regIncludeChars.test(input) &&
      input.length>=8 && 
      level = 3;

    return level;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment