EditText – Limit with ALL CAPITALS with NOSPACES

How to restrict EditText with all character capital with no space between?

Below is customize InputFiler use for this:

public static class NoSpaceWithAllCaps implements InputFilter {
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
for (int i = start; i < end; i++) {
if (Character.isWhitespace(source.charAt(i))) {
return “”;
}
if (Character.isLowerCase(source.charAt(i))) {
char[] v = new char[end – start];
TextUtils.getChars(source, start, end, v, 0);
String s = new String(v).toUpperCase();

if (source instanceof Spanned) {
SpannableString sp = new SpannableString(s);
TextUtils.copySpansFrom((Spanned) source,
start, end, null, sp, 0);
return sp;
} else {
return s;
}
}
}

return null;
}
}

You may also like

Leave a Reply