Alex Rivera | Logout

How to restrict special characters from an Android EditText field?

Asked 2010-08-02T06:55:44.970
33

How to restrict special characters from an Android EditText field?

Edit
Report

1 Answer

47

Have you tried adding the android:digits="abcde.....0123456789" attribute? Although the android:digits specify that it is a numeric field, it does work for me to set it to accept letters as well, and special characters as well (tested on SDK-7).

If this doesn't work then you'll have to implement KeyListener see: http://developer.android.com/reference/android/widget/TextView.html#setKeyListener(android.text.method.KeyListener)

answered 2010-08-02T07:08:46.753

Your Answer