Table of Contents
This project gives a simple and streamlined way to validate TextInputLayoutEditText
Installation
- Insert the JitPack repository to your develop file
allprojects
repositories
...
maven url 'https://jitpack.io'
- Incorporate the dependency
dependencies
implementation 'com.github.BrianHardyR:TextInputLayoutValidator:1.1.2'
How to
Simple Validation
val myinput = findViewById<TextInputLayout>(R.id.my_enter)
myinput.validate(
default = "my default text",
validators = listOf(
text -> t.isNotEmpty() ,
...
),
error = "my error textual content",
onValid = validText ->
// do one thing with the legitimate text
)
Employing the Validation Item
Error information for each individual validation affliction
val phoneNumberValidator = TextInputValidator(
defaultString = "My default text",
validators = listOf(
textual content -> (textual content.duration > 12) to "Length have to be greater than 12",
text -> text.startsWith('+') to "Input will have to begin with '+'",
...
)
)
Solitary error message
val phoneNumberValidator = TextInputValidationObj(
default = "My default textual content",
mistake = "Remember to enter a legitimate cellphone selection",
validators = listOf(
text -> text.duration > 12,
text -> text.startsWith('+'),
...
)
)
myinput.validate(phoneNumberValidator) validText ->
// do a thing with the legitimate textual content
Validate enter After location the validation object on the TextInputLayout you can validate it anyplace on your code
myinput.legitimate() // Return a Boolean.