Reputation: 9394
I have an issue when user try to enter text copied that this text sometimes contains some special characters like �
and this make JSON string to be not formated, so please how can I avoid user enter such characters
please take into consideration that user can enter Arabic text and English text only
Upvotes: 0
Views: 146
Reputation: 442
Try using InputFilters on the Edittext:
InputFilter filter = new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = start; i < end; i++) {
if (isEnglishOrArabicChar(source.charAt(i))) {
stringBuilder.append(source.charAt(i));
}
}
return stringBuilder.toString();
}
};
etName.setFilters(new InputFilter[]{filter});
private static boolean isEnglishOrArabicChar(char c) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
return ub == Character.UnicodeBlock.ARABIC || ub==Character.UnicodeBlock.BASIC_LATIN;
}
Upvotes: 3