6

I want to make an EditText box and use TextWatcher to prevent typing of special characters.

gobernador
  • 5,659
  • 3
  • 32
  • 51
Sourav301
  • 1,259
  • 1
  • 14
  • 24

1 Answers1

7

This is for only character and space validation...

InputFilter filter = new InputFilter()     
{  
    @Override  
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)   
    {   
        for (int i = start; i < end; i++)
            if (!Character.isLetter(source.charAt(i)) && !Character.isSpaceChar(source.charAt(i)))
                return "";

        return null;  
    }
};

myTextView.setFilters(new InputFilter[] { filter });
Kamran Ahmed
  • 7,661
  • 4
  • 30
  • 55
Dipak Sonnar
  • 193
  • 2
  • 7