I want to define a min and max value for an EditText
.
For example: if any person tries to enter a month value in it, the value must be between 1-12.
Very simple example on Kotlin:
import android.text.InputFilter
import android.text.Spanned
class InputFilterRange(private var range: IntRange) : InputFilter {
override fun filter(source: CharSequence, start: Int, end: Int, dest: Spanned, dstart: Int, dend: Int) = try {
val input = Integer.parseInt(dest.toString() + source.toString())
if (range.contains(input)) null else ""
} catch (nfe: NumberFormatException) {
""
}
}