int maxLength = 20;
private String blockCharacterSet = "~#^|$%'&*!;";
private InputFilter filter = new InputFilter()
{
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
{
if (source != null && blockCharacterSet.contains(("" + source))) {
return "";
}
return null;
}
};
Here only one filter is working either blockCharacterSet or max length:
EditText etname;
etname.setFilters(new InputFilter[] { filter });
etname.setFilters(new InputFilter[] {new InputFilter.LengthFilter(maxLength)});
Can anyone please help me to set above two filters at a time?
If you have two inputFilters, add it in array like below:
etname.setFilters(new InputFilter[] {
new InputFilter.LengthFilter(maxLength), filter});
Finally the setFilter()
takes array of input filters, so in the array you create in setFilters()
should contain all the input filters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With