Search code examples
javaandroidandroid-textinputedittext

How to restrict specific words or numeric sequence in editText?


in android is it possible to restrict edittext in order to reject and show an alert if some words are entered? For example I need to exclude from the edittext input the following words and numerc sequences: "123456", "0000", "administrator", "black" etc. Someone can help me please?

I used the following code to check and show alert when edittext is blank

    if (TextUtils.isEmpty(name)) {
        editTextName.setError("Please enter name");
        editTextName.requestFocus();
        return;
    }

but I don't know how to check if was entered restricted words.

Thanks Andrew


Solution

  • Implement a TextWatcher to your EditText addTextChangedListener and on

    beforeTextChanged(CharSequence s, int start, int count, int after)
    

    check if the input is the one you trying to reject.