Skip to content Skip to sidebar Skip to footer

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 ?

Solution 1:

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 backspacereturn src;
        }
        if(src.toString().matches("[\\x00-\\x7F]+")){
            return src;
        }
        return"";
    }
 }
});

Solution 2:

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?

Post a Comment for "Android Edittext : How To Avoid User Enter Smileys?"