I would like to avoid to the user to put a smiley with the keyboard into an EditText
. Is it possible ?
Asked
Active
Viewed 8,337 times
4

wawanopoulos
- 9,614
- 31
- 111
- 166
-
1can you say clearly pls? – Achiever Jun 27 '14 at 09:06
-
you just want to avoid smilies and allow every thing or you just to allow text + numbers only (not special characters)? please clarify. – SMR Jun 27 '14 at 09:23
-
Yes, just want to avoid smilies and allow every thing – wawanopoulos Jun 27 '14 at 09:28
-
1This question is quite obvious to me, why is this downvoted so much. Have a +1 on me – Mathijs Segers Jul 29 '15 at 08:32
-
**Kotlin Solution here** - https://stackoverflow.com/a/52947835/3333878 – abitcode Oct 23 '18 at 11:34
2 Answers
13
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 "";
}
}
});

Community
- 1
- 1

KRUPEN GHETIYA
- 211
- 2
- 6
-
I simply did: `return source.toString().matches("\\S") ? source : "";` and it is working. The \S allows anything but white-space (line breaks, tabs, spaces, hard spaces). – Dick Lucas Nov 01 '16 at 16:05
-
-
1but when you click emoji, then click backspace, 2 characters will be deleted from the current text – HendraWD May 29 '17 at 13:30
0
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:

Community
- 1
- 1

TheOnlyJakobob
- 541
- 3
- 14