0

I trying validate password and the conditions are

1- A-a

2- 0- 9

3- Special characters

The first and second conditions work fine with this expression

(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,16})$

But i dont know implement the third condition.

My Method

public static boolean PasswordStrong(String pass) {
    String expresion = "(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,16})$";
    Pattern patron = Pattern.compile(expresion);
    Matcher m = patron.matcher(pass);
    if (m.find())
        return true;
    return false;
}
Pshemo
  • 122,468
  • 25
  • 185
  • 269
David Hackro
  • 3,652
  • 6
  • 41
  • 61

1 Answers1

1

I Solved again my question >.<

i use this expression

((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})

more examples you can find with mkyong

David Hackro
  • 3,652
  • 6
  • 41
  • 61