-1

Criteria to achieve with regex pattern for the input text is,

  • Support at-least one Uppercase letter
  • Support at-least one Lowercase letter
  • Support at-least one Special character listed --> @ % $
  • Support at-least one Digit

No Start and End Criteria.

Trying to achieve with below single regex,

^(
  (\w+\d+[@%\$]+)
     |
     (\d+[@%\$]+\w+)
        |
        ([@%\$]+\d+\w+)
             |
             (\w+[@%\$]+\d+)
)$

Problem is,

Support for at-least one uppercase is not working. I am pretty sure that it is not a good approach to build the regex pattern.

Please help me to achieve these criteria in single regex pattern.

Thanks in Advance!!!

Pass Criteria

Test@123
tesT@123
@123tesT
123@Test
TTTTeeeess@@@@$$$111112222
@@@@$$$1111TTT@@@$$esss

Fail Criteria

Test (No special character)
@123
123
@
T
test
test@123 (No Uppercase)
Test@123& ('&' not to be supported in the pattern)
@123test
@TTT123 (No Lowercase)

Nike
  • 25
  • 5
  • Pass and Fail Criteria are different from the other related questions.(Solutions cant be achieved). Hence, it is not a duplicate. – Nike Jan 21 '15 at 11:11
  • Tweeking the solutions provided in that questions are quite complicate for me where the answer is not easily understood by me. Apologize for that. – Nike Jan 21 '15 at 11:13

2 Answers2

0
^(?=.*[A-Z])(?=.*\d)(?=.*[a-z])(?=.*[@%$]).+$

Try this.This should do it.Each condition is satisfied using lookaheads.

See demo.

https://regex101.com/r/tX2bH4/70

vks
  • 67,027
  • 10
  • 91
  • 124
0

There's a better way to do this, using lookaheads:

^
(?=.*[A-Z])
(?=.*[a-z])
(?=.*[@%$])
(?=.*\d)
.*$
Aran-Fey
  • 39,665
  • 11
  • 104
  • 149