My Password should be Like :
"Password should contain at least one uppercase letter, one lowercase letter, one digit and one special character with minimum eight character length"
The Pattern I have used is : ^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[$@$#!%*?&])[A-Za-z\\d$@$#!%*?&]{8,}
So, I have created a function as below in my Constant.java file :
public static Boolean passwordMatcher(TextInputLayout edtText,String string) {
Pattern pattern = Pattern.compile("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\\\d)(?=.*[$@$#!%*?&])[A-Za-z\\\\d$@$#!%*?&]{8,}");
Matcher matcher = pattern.matcher(edtText.getEditText().getText().toString());
boolean isMatched = matcher.matches();
if (isMatched) {
return true;
}
if (!isMatched) {
edtText.setErrorEnabled(true);
edtText.setError("" + string);
edtText.setFocusable(true);
return false;
}
return true;
}
and in my MainActivity.java file I have checked for validation as below :
if (!Constant.passwordMatcher(edtPassword, mContext.getResources().getString(R.string.error_activity_signup_password_invalid))) {
return;
}
But, I am not getting success even if I have tried : 'Jaimin123#' as a my password. Always getting error set in my TextInputLayout.
What might be the issue ?
Thanks.