RegEx question for password strength validation

后端 未结 2 871
醉酒成梦
醉酒成梦 2021-01-05 22:49

I\'m looking for a single regular expression for our password requirements. Passwords:

  • Must be at least 8 characters
  • Cannot contain spaces
  • Co
相关标签:
2条回答
  • 2021-01-05 23:33

    It'll probably be easier to code the logic. Regex is used for matching patterns. Passwords tend to be somewhat random strings, so the problem doesn't lend itself easily to be solved by a regex. It's possible but will be cryptic to read and hard to maintain.

    0 讨论(0)
  • 2021-01-05 23:41

    Idea and most of the work taken from http://www.zorched.net/2009/05/08/password-strength-validation-with-regular-expressions/

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

    I used the basic answer at the bottom of his post, but replaced all the dots with \S to rule out space characters, and moved around some of the assertions.

    0 讨论(0)
提交回复
热议问题