Is it possible to have list of InputFilters for example only letting inputs such as
$1,01
or $100,95
that was done with
editText.filters = arrayOf(CurrencyFormatInputFilter(), InputFilter.LengthFilter(8))
class CurrencyFormatInputFilter : InputFilter {
private val pattern = Pattern.compile(CURRENCY_INPUT_REGEX)
override fun filter(
source: CharSequence,
start: Int,
end: Int,
dest: Spanned,
dstart: Int,
dend: Int
): CharSequence? {
val result = (dest.subSequence(0, dstart).toString()
+ source.toString()
+ dest.subSequence(dend, dest.length))
val matcher = pattern.matcher(result)
return if (!matcher.matches()) dest.subSequence(dstart, dend) else null
}
}