How to disable the input in EditText any characters except the characters of the alphabet? The alphabets belong to an arbitrary number of languages. All considered characters are included in Unicode .

  • android: digits = "abcdefghijklmnopqrstuvwxyz" - Serodv
  • If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - DevOma

2 answers 2

If you need only Latin letters, then in xml add:

 android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 

Otherwise

 EditText state = (EditText) findViewById(R.id.txtState); Pattern ps = Pattern.compile("^[a-zA-Z ]+$"); Matcher ms = ps.matcher(state.getText().toString()); boolean bs = ms.matches(); if (bs == false) { if (ErrorMessage.contains("invalid")) ErrorMessage = ErrorMessage + "state,"; else ErrorMessage = ErrorMessage + "invalid state,"; } 

The answer is taken from here.

     InputFilter filter = new InputFilter() { public CharSequence filter(CharSequence src, int start, int end, Spanned d, int dstart, int dend) { for (int i = start; i < end; i++) { if (!Character.isLetter(src.charAt(i))) { return src.subSequence(start, i-1); } } return null; } }; edit.setFilters(new InputFilter[]{filter});