4

i want to make a edit text in which can only be able to enter only alphabatical character means from a-z no other numeric or special charaacter are not allowed so how to do it?

i had 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 accept all the values means numeric and special character also.so how to restrict it means user can only enter a-z values.

shyam
  • 1,276
  • 4
  • 25
  • 51

4 Answers4

3

Type in your xml respective EditText....

android:digits="abcdefghijklmnopqrstuvwxyz"

EditText will not accept digits or special character but alphabets only..

Naveed Ashraf
  • 295
  • 2
  • 6
2

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}); 
shyam
  • 1,276
  • 4
  • 25
  • 51
1

see the InputType in android this is the reference Input Type API

Parag Chauhan
  • 35,760
  • 13
  • 86
  • 95
0

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

android:digits="abcdefghijklmnopqrstuvwxyz " 

Note that white space at the end of abcd... string.

Yurii
  • 4,811
  • 7
  • 32
  • 41
user3775481
  • 109
  • 1
  • 3