开发者

RegEx to validate a string, whether it contains at least one lower case char, upper case char, one digit,one symbol and no whitespace [duplicate]

开发者 https://www.devze.com 2023-03-16 08:22 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: RegEx to make sure that the string contains at least one lower case char, upper case char, digit and symbol
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

RegEx to make sure that the string contains at least one lower case char, upper case char, digit and symbol

What would be th开发者_JS百科e regex to make sure that a given string contains at least one character from each of the followings ---

  • upper case letter
  • lower case letter
  • no whitespace
  • digit
  • symbol
  • string length is >=5 and <=10

how to combine all these above criteria to validate a string.


If it has to be a regex:

^            # Start of string
(?=.*[A-Z])  # upper case (ASCII) letter
(?=.*[a-z])  # lower case letter
(?=.*\d)     # digit
(?=.*[\W_])  # symbol
\S           # no whitespace
{5,10}       # string length is >=5 and <=10
$            # end of string

or, if your regex flavor doesn't support verbose regexes:

^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[\W_])\S{5,10}$
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号