Validator Class
This section describes how to perform validation checks using Validator class
Basic Concepts
The EasyValidation
library performs all the validation checks based on the Validator
class. You can easily perform validations on any String
using this class.
The easiest way to validate any string is to create an Object
of Validator
class and pass any String
in it and then you can perform validation checks.
Now, the Validator
class contains a lot of built-in rules in form of methods. For example, to check valid email, you can use validEmail()
method, or check non-empty String
, you can use nonEmpty()
method and so on. Each method returns a Boolean
value, where true
means String
is valid and false
means String
is not valid. For example:
Also, each method has an optional error callback method. This will be called in case on non-valid String
. For example:
Error and Success Callbacks
The Validator
class provides callback methods with addErrorCallback()
and addSuccessCallback()
methods. For example:
Validator Extensions
You can access the Validator object by using Kotlin extension methods on String
, EditText
, TextView
, AutoCompleteTextView
, TextInputLayout
, and Spinner
using validator()
method. For example:
Adding Rules Manually
You can add built-in rules or custom rules by calling addRule()
method of the Validator
class.
Last updated