Extension Methods
This section describes how to use Kotlin extension methods for validation checks.
Last updated
This section describes how to use Kotlin extension methods for validation checks.
Last updated
EasyValidation utilizes the power of Kotlin Extension methods and provides you huge number of built-in validation rules in form of extensions on String
, EditText
, TextView
, AutoCompleteTextView
, TextInputLayout
, and Spinner
classes.
For example, you can check some validation checks on EditText
like this:
Here is the list of all extension methods for String
, EditText
, TextView
, AutoCompleteTextView
, TextInputLayout
, and Spinner
classes.
Method
Description
validator()
Returns the Validator
object with text
nonEmpty()
Returns true
if the text is not empty. And returns false
if text is empty.
minLength()
Returns false
if the length of text is less than given minimum length.
maxLength()
Returns false
if text length is greater than given length
validEmail()
Returns true
if text is a valid email address.
validNumber()
Returns true
if the text is any valid number
greaterThan()
Returns false
if the text is number less than the given target number
greaterThanOrEqual()
Returns false
if the text is number less than or equal to the given target number
lessThan()
Returns false
if the text is number greater than the given target number
lessThanOrEqaul()
Returns false
if the text is number greater than or equal to the given target number
numberEqualTo()
Returns false
if the text is a valid number and equal to the given target number
allUperCase()
Returns false
if at least one or more characters are lower case
allLowerCase()
Returns false
if at least one or more characters are upper case
atleastOneUperCase()
Returns true
if at least one or more characters are upper case
atleastOneLowerCase()
Returns true
if at least one or more characters are lower case
atleastOneNumber()
Returns true
if at least one or more characters are numbers
startWithNumber()
Returns true
if text starts with any number
startWithNonNumber()
Returns false
if text starts with any number
noNumbers()
Returns false
if the text any number or digit.
onlyNumbers()
Returns false
if text contains any alphabetic character
noSpecialCharacters()
Returns true
if text contain no special characters
atleastOneSpecialCharacters()
Returns true
if text contain at least one special characters
textEqaulTo()
Returns false
if the text is not equal to the given text
textNotEqualTo()
Returns true
if the text is not equal to the given text
startsWith()
Returns true
if the text starts with the given text
endsWith()
Returns true
if the text ends with the given text
contains()
Returns true
if the text contains the given text
notContains()
Returns false
if the text contains the given text
creditCardNumber()
Returns true
if the text is valid credit card number. This supports Visa, Master Card, American Express, Diners Club, Discover, and JCB.
creditCardNumberWithSpaces()
Returns true
if the text is valid credit card number with spaces between 4 characters. This supports Visa, Master Card, American Express, Diners Club, Discover and JCB.
creditCardNumberWithDashes()
Returns true
if the text is valid credit card number with dashes between 4 characters. This supports Visa, Master Card, American Express, Diners Club, Discover, and JCB.
validUrl()
Returns true
if the text is a valid URL
regex()
Returns true
if the text matches passed RegEx
pattern.