Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 763
wawanopoulos Avatar asked Dec 11 '22 05:12

wawanopoulos


1 Answers

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 "";
    }
 }
});
like image 66
KRUPEN GHETIYA Avatar answered Jan 14 '23 19:01

KRUPEN GHETIYA