EditText - Allow Only Specific Characters Known From Context
In my app i have EditText. I want user to be able to insert only digits and two characters specified by me. I know there exists android:digits='...' but I can't use this because i
Solution 1:
This is the proper way to do such task
InputFilter filter = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
for (int i = start; i < end; i++) {
// Your condition here
if (!Character.isLetterOrDigit(source.charAt(i))) {
return "";
}
}
return null;
}
};
edit.setFilters(new InputFilter[]{filter});
Solution 2:
see my answer here how to create custom InputFilter InputFilter on EditText cause repeating text, of course you have to modify a bit filtering condition
Post a Comment for "EditText - Allow Only Specific Characters Known From Context"