Hi I am very new for android and in my app I have Validations for Change password page.
That means the Password must contain minimum 8 characters at least 1 Alphabet, 1 Number and 1 Special Character, for this I tried the code below, but it's not working.
Please help me.
if(!isPasswordValidMethod(newPassword.getText().toString())){
System.out.println("Not Valid");
}else{
System.out.println("Valid");
}
// Validate password
private boolean isPasswordValidMethod(String password) {
String yourString = newPassword.getText().toString();
System.out.println("yourString is =" + yourString);
boolean isValid = false;
// ^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$
// ^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$
String expression = "^(?=.*[A-Za-z])(?=.*\\\\d)(?=.*[$@$!%*#?&])[A-Za-z\\\\d$@$!%*#?&]{8,}$";
CharSequence inputStr = password;
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches()) {
System.out.println("if");
isValid = true;
}else{
System.out.println("else");
}
return isValid;
}