Create edit text only accept or enter only alphabetical character from az for android only

I want to make editable text in which only alphabetic characters from az can be entered, no other numeric or special characters are allowed, so how do I do this?

I tried

<EditText **android:inputType="text"** android:id="@+id/state" android:singleLine="true" android:layout_marginTop="50dip" android:layout_marginLeft="100dip" android:layout_height="40dip" android:layout_width="200dip" /> 

but it takes all values, it means a numerical and special character. Also, how to limit it means that the user can enter only az values.

+4
source share
4 answers

see InputType in android, this is an input type API reference

+1
source

Enter your xml corresponding to EditText ....

Android: numbers = "ABVGDEZHZIKLMNOPRSTUFHCHSHEYUA"

EditText will not accept numbers or special characters except letters.

+3
source

I did it using

  @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))) { return ""; } } return null; } }; EditText etcity= ((EditText) findViewById(R.id.city)); etcity.setFilters(new InputFilter[]{filter}); 
+2
source

If you want EditTest to have only characters with spaces, use this:

 android:digits="abcdefghijklmnopqrstuvwxyz " 

Note that the space at the end of the line is abcd...

0
source

All Articles