Create Custom Rules
This section describes how to create your own custom rules.
class HelloRule : BaseRule
{
// add your validation logic in this method
override fun validate(text: String) : Boolean
{
// Apply your validation rule logic here
return text.contains("hello")
}
// Add your invalid check message here
override fun getErrorMessage() : String
{
return "Text should contain 'hello' keyword"
}
}var myEditText = findViewById<EditText>(R.id.myEditText)
var myEditText.validator()
.addRule(HelloRule())
.addErrorCallback {
// In case of invalid, this method will be called.
// The 'it' will be "Text should contain 'hello' keyword" message.
myEditText.error = it
}
.check()Last updated