1

I want to restric user from entering any special character or number into edit text, but programmatically it should allow.

I know I can make inputType="text" but it deals only with the softkeyboard. I think it can be achived with TextWatcher, but I am not able to gel evrything. Can anyone help ?

Shardul
  • 786
  • 3
  • 11
  • 20

3 Answers3

1

You can filter input text by following ,

etTwamboxName.setFilters(new InputFilter[] { new InputFilter() {
            public CharSequence filter(CharSequence src, int start, int end,
                    Spanned dst, int dstart, int dend) {

                Log.e("", "===> " + src);
                if (src.equals("")) { // for backspace
                    return src;
                }

                if (src.toString().matches("[a-zA-Z ]+.")) {
                    return src;
                }

                return "";
            }
        } });
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
Chirag
  • 2,321
  • 24
  • 36
1

Try this way,Reference

android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
android:inputType="text"

For more info, you may check http://developer.android.com/reference/android/widget/TextView.html#attr_android:digits

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
1
editTextView.setInputType(InputType.TYPE_TEXT_VARIATION_NORMAL);

There are many other types of inputs available for Password, Email address etc. Please see This API Link

Thanks :)

Piyush Patel
  • 1,765
  • 1
  • 16
  • 29
  • Thankx but thats the default behavior, I want to make it character only. No numbers or special characters. Character which range A-Z. I achived it with TextWatcher. Thanx anyways. – Shardul Nov 26 '10 at 07:21