Используйте регулярное выражение (регулярное выражение), чтобы определить формат пароля. Пример пароля регулярного выражения:
^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\S+$).{8,}$
^ # start-of-string
(?=.*[0-9]) # a digit must occur at least once
(?=.*[a-z]) # a lower case letter must occur at least once
(?=.*[A-Z]) # an upper case letter must occur at least once
(?=.*[@#$%^&+=]) # a special character must occur at least once
(?=\S+$) # no whitespace allowed in the entire string
.{8,} # anything, at least eight places though
$
# end-of-string
Добавьте TextWatch к вашему EditText, чтобы наблюдать за изменением текста при его вводе
yourEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
Pattern PASSWORD_PATTERN = Pattern.compile("Your pattern");
if (PASSWORD_PATTERN.matcher(s.toString()).matches()) {
//Password is valid, move to new activity
}
}
});
Все просто с regex bro!