Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters

前端 未结 30 3729
伪装坚强ぢ
伪装坚强ぢ 2020-11-21 04:28

I want a regular expression to check that:

A password contains at least eight characters, including at least one number and includes both lower and uppercase letter

30条回答
  •  爱一瞬间的悲伤
    2020-11-21 05:06

    A more "generic" version(?), allowing none English letters as special characters.

    ^(?=\S*[a-z])(?=\S*[A-Z])(?=\S*\d)(?=\S*[^\w\s])\S{8,}$
    

    var pwdList = [
        '@@V4-\3Z`zTzM{>k',
        '12qw!"QW12',
        '123qweASD!"#',
        '1qA!"#$%&',
        'Günther32',
        '123456789',
        'qweASD123',
        'qweqQWEQWEqw',
        '12qwAS!'
      ],
      re = /^(?=\S*[a-z])(?=\S*[A-Z])(?=\S*\d)(?=\S*[^\w\s])\S{8,}$/;
      
      pwdList.forEach(function (pw) {
        document.write('' + pw + '
    '); });

提交回复
热议问题