[ad_1]
This venture gives a easy and streamlined solution to validate TextInputLayoutEditText
Set up
- Add the JitPack repository to your construct file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency
dependencies {
implementation 'com.github.BrianHardyR:TextInputLayoutValidator:1.1.2'
}
The way to
Easy Validation
val myinput = findViewById<TextInputLayout>(R.id.my_input)
myinput.validate(
default = "my default textual content",
validators = listOf(
{ textual content -> t.isNotEmpty() },
...
),
error = "my error textual content",
onValid = { validText ->
// do one thing with the legitimate textual content
}
)
Utilizing the Validation Object
Error message for every validation situation
val phoneNumberValidator = TextInputValidator(
defaultString = "My default textual content",
validators = listOf(
{ textual content -> (textual content.size > 12) to "Size have to be better than 12"},
{ textual content -> textual content.startsWith('+') to "Enter should begin with '+'"},
...
)
)
Single error message
val phoneNumberValidator = TextInputValidationObj(
default = "My default textual content",
error = "Please enter a sound cellphone quantity",
validators = listOf(
{ textual content -> textual content.size > 12},
{ textual content -> textual content.startsWith('+')},
...
)
)
myinput.validate(phoneNumberValidator){ validText ->
// do one thing with the legitimate textual content
}
Validate enter After setting the validation object on the TextInputLayout you possibly can validate it wherever in your code
myinput.legitimate() // Return a Boolean.
[ad_2]
Source_link