1

I'm trying to develop a regular expression for validating a password which should meet following criteria

  • should have at least one Uppercase letter,
  • should have at least one Lowercase letter,
  • should have at least one Special character,
  • should have at least one digit,
  • must be minimum 6 characters long.

I have developed a expression for that:

password_pattern=/^(?=.*[0-9]) (?=.*[!@#$%^&*]) (?=.*[a-z]) (?=.*[A-Z]) {6} $/

However it is not working as I intended. What am I going wrong?

I'm new to regular expressions, so I'd appreciate an explanation rather than a 'use this' sort of answer, please explain.

Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504

1 Answers1

1

You are missing a single dot before the {6}, and you've added spaces, which you shouldn't have:

password_pattern=/^(?=.*[0-9])(?=.*[!@#$%^&*])(?=.*[a-z])(?=.*[A-Z]).{6}$/
Bohemian
  • 412,405
  • 93
  • 575
  • 722