An interface for input validation used in setInputValidator.
An input validator can validate the action before it’s actually performed on the underlying editor. Returning false on any validation will discard the action.
interface InputValidator {
fun validateInput(label: String, keyCode: Int): Boolean
}
validateInput | Invoked on every key tap or button and backspace gesture. |
defaultInputValidator | Default implementation of an InputValidator. |
Validates a key tap on buttons, letters, punctuation, or emojis. Returns whether the action has been accepted or not.
fun validateInput(label: String, keyCode: Int) : Boolean
The label contains the text shown in the key being tapped.
The keyCode contains the code related to the key or button being pressed. For emojis, the keyCode is the ascii code for the first UTF8 character of the emoji.
Special button keyCodes:
Label | Key Code |
---|---|
shift | -1 |
symbols letters numbers |
-3 |
backspace | 8 |
enter | 13 |
space | 32 |
<Other buttons> | 0 |
A convenience default implementation of an InputValidator, with every interface function returning true. It is preferable to use this implementation in case new validations are added in future releases.
abstract class DefaultInputValidator : InputValidator {
override fun validateInput(label: String) = true
}