Password validation regex

后端 未结 2 855
半阙折子戏
半阙折子戏 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 07:58

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

    should do. Be aware, though, that you're only validating ASCII letters. Is Ä not a letter for your requirements?

    \S means "any character except whitespace", so by using this instead of the dot, and by anchoring the regex at the start and end of the string, we make sure that the string doesn't contain any whitespace.

    I also removed the unnecessary parentheses around the entire expression.

提交回复
热议问题