2

Here is my validate method

public boolean isValidPassword(final String password) {

    Pattern pattern;
    Matcher matcher;

    final String PASSWORD_PATTERN = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).{8,}$";

    pattern = Pattern.compile(PASSWORD_PATTERN);
    matcher = pattern.matcher(password);

    return matcher.matches();

}

From above code I need to must enter at least 1 digit, 1 lower, 1 upper, 1 special. but i need to give choice to user enter any 3 choices out of 4 .. i.e..... 1 digit, 1 upper, 1 lower (or) 1 special, 1 digit, 1 upper...etc

reVerse
  • 35,075
  • 22
  • 89
  • 84
Dolly Rosy
  • 140
  • 10

1 Answers1

1

Use this:

"^(?=.*?[A-Za-z0-9])(?=.*?[A-Z#?!@$%^&*-0-9])(?=.*?[a-z#?!@$%^&*-0-9])(?=.*?[A-Za-z#?!@$%^&*-]).{8,20}$"
Dolly Rosy
  • 140
  • 10