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
String validPassword = "12345";
_Password_String = Password.getText().toString();
Matcher matcher = Pattern.compile(validPassword).matcher(_Password_String);
if (matcher.matches()) {
Log.e("d11", _Password_String);
Toast.makeText(getActivity(), "Password Match", Toast.LENGTH_LONG).show();
getFragmentManager().popBackStack();
} else {
Password.setError("Password");
Toast.makeText(getActivity(), "Password not Match", Toast.LENGTH_LONG).show();
}
try following Code
//*****************************************************************
public static boolean isValidPassword(final String password) {
Pattern pattern;
Matcher matcher;
final String PASSWORD_PATTERN = "^(?=.*[0-9])(?=.*[A-Z])(?=.*[@#$%^&+=!])(?=\\S+$).{4,}$";
pattern = Pattern.compile(PASSWORD_PATTERN);
matcher = pattern.matcher(password);
return matcher.matches();
}
And change your code to this
if(newPassword.getText().toString().length()<8 &&!isValidPassword(newPassword.getText().toString())){
System.out.println("Not Valid");
}else{
System.out.println("Valid");
}