wawanopoulos
wawanopoulos

Reputation: 9804

Android EditText : How to avoid user enter smileys?

I would like to avoid to the user to put a smiley with the keyboard into an EditText. Is it possible ?

enter image description here

Upvotes: 5

Views: 8561

Answers (2)

KRUPEN GHETIYA
KRUPEN GHETIYA

Reputation: 221

Editing answer from here.

This will allow only ASCII characters to be entered in EditText.

edittext.setFilters(new InputFilter[] {
 new InputFilter() {
    public CharSequence filter(CharSequence src, int start,
            int end, Spanned dst, int dstart, int dend) {
        if(src.equals("")){ // for backspace
            return src;
        }
        if(src.toString().matches("[\\x00-\\x7F]+")){
            return src;
        }
        return "";
    }
 }
});

Upvotes: 13

TheOnlyJakobob
TheOnlyJakobob

Reputation: 541

You can define your input type and only accept letters or change your keyboard type:

https://developer.android.com/training/keyboard-input/style.html

Or you can only accept some specific digits:

How to create EditText accepts Alphabets only in android?

Upvotes: 0

Related Questions