0

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 the 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.

Community
  • 1
  • 1
Neel
  • 429
  • 7
  • 17

1 Answers1

10

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}$
Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561