0

Conditions for password

  1. Minimum length should be 7
  2. It must contain at-least one Capital letter
  3. It must contain at-least one numeric
  4. It must contain at-least one special character

/^(?=.{7,50}$)(?=.*[0-9])(?=.*[!@#$%^&*_])(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9!@#$%^&*_].*/

It is working for passwords Mouse@123 but not working for Mouse_123

  • Possible duplicate of [Regex for Password Must be contain at least 8 characters, least 1 number and both lower and uppercase letters and special characters](http://stackoverflow.com/questions/19605150/regex-for-password-must-be-contain-at-least-8-characters-least-1-number-and-bot) – Vegeta Jan 19 '16 at 07:12
  • What is your question? –  Jan 19 '16 at 08:09
  • Edited my question.pls suggest – DurgaPrasad9v Jan 19 '16 at 14:02

1 Answers1

1

Your regex can be simplified to this:

/^(?=.*\d)(?=.*[!@#$%^&_])(?=.*[A-Z])[a-zA-Z\d!@#$%^&_]{7,50}$/

You need not have (?=.*{7,50}$) lookahead as that can be done outside as well. Besides requirement of at least one small letter is not there in your question.

anubhava
  • 761,203
  • 64
  • 569
  • 643