Password validation regex

后端 未结 2 840
半阙折子戏
半阙折子戏 2020-11-27 07:15

I am trying to get one regular expression that does the following:

  1. makes sure there are no white-space characters
  2. minimum length of 8
  3. makes s
2条回答
  •  死守一世寂寞
    2020-11-27 08:09

    Tim's answer works well, and is a good reminder that there are many ways to solve the same problem with regexes, but you were on the right track to finding a solution yourself. If you had changed (?!\s) to (?!.*\s) and added the ^ and $ anchors to the end, it would work.

    ^((?=.*[^a-zA-Z])(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{8,})$
    

提交回复
热议问题