Toasts
This section describes how to use Kotlin extension methods for validation checks, which displays errors in the Toast messages.
Overview
EasyValidation utilizes the power of Kotlin Extension methods and provides you a huge number of built-in validation rules in the form of extensions on String
, EditText
, TextView
, AutoCompleteTextView
, TextInputLayout
, and Spinner
classes.
This page explains about a Toasts
module, which is the part of EasyValidation and automatically displays all the validation errors in the Toast
message by default.
Installation
Add this in your app-level build.gradle
file.
And now you can use the extention methods with are like **Toast(
) on String
, EditText
, TextView
, AutoCompleteTextView
, TextInputLayout
, and Spinner
classes.
For example, you can check some validation checks on EditText
like this:
List of Extension Methods
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
nonEmptyToast()
Returns true
if the text is not empty. And returns false
if text is empty.
Also displays the Toast
message with the error.
minLengthToast()
Returns false
if the length of text is less than given minimum length.
Also displays the Toast
message with the error.
maxLengthToast()
Returns false
if text length is greater than given length
Also displays the Toast
message with the error.
validEmailToast()
Returns true
if text is a valid email address.
Also displays the Toast
message with the error.
validNumberToast()
Returns true
if the text is any valid number
Also displays the Toast
message with the error.
greaterThanToast()
Returns false
if the text is number less than the given target number
Also displays the Toast
message with the error.
greaterThanOrEqualToast()
Returns false
if the text is number less than or equal to the given target number
Also displays the Toast
message with the error.
lessThanToast()
Returns false
if the text is number greater than the given target number
Also displays the Toast
message with the error.
lessThanOrEqaulToast()
Returns false
if the text is number greater than or equal to the given target number
Also displays the Toast
message with the error.
numberEqualToToast()
Returns false
if the text is a valid number and equal to the given target number
Also displays the Toast
message with the error.
allUperCaseToast()
Returns false
if at least one or more characters are lower case
Also displays the Toast
message with the error.
allLowerCaseToast()
Returns false
if at least one or more characters are upper case
Also displays the Toast
message with the error.
atleastOneUperCaseToast()
Returns true
if at least one or more characters are upper case
Also displays the Toast
message with the error.
atleastOneLowerCaseToast()
Returns true
if at least one or more characters are lower case
Also displays the Toast
message with the error.
atleastOneNumberToast()
Returns true
if at least one or more characters are numbers
Also displays the Toast
message with the error.
startWithNumberToast()
Returns true
if text starts with any number
Also displays the Toast
message with the error.
startWithNonNumberToast()
Returns false
if text starts with any number
Also displays the Toast
message with the error.
noNumbersToast()
Returns false
if the text any number or digit.
Also displays the Toast
message with the error.
onlyNumbersToast()
Returns false
if text contains any alphabetic character
Also displays the Toast
message with the error.
noSpecialCharactersToast()
Returns true
if text contain no special characters
Also displays the Toast
message with the error.
atleastOneSpecialCharactersToast()
Returns true
if text contain at least one special characters
Also displays the Toast
message with the error.
textEqaulToToast()
Returns false
if the text is not equal to the given text
Also displays the Toast
message with the error.
textNotEqualToToast()
Returns true
if the text is not equal to the given text
Also displays the Toast
message with the error.
startsWithToast()
Returns true
if the text starts with the given text
Also displays the Toast
message with the error.
endsWithToast()
Returns true
if the text ends with the given text
Also displays the Toast
message with the error.
containsToast()
Returns true
if the text contains the given text
Also displays the Toast
message with the error.
notContainsToast()
Returns false
if the text contains the given text
Also displays the Toast
message with the error.
creditCardNumberToast()
Returns true
if the text is valid credit card number. This supports Visa, Master Card, American Express, Diners Club, Discover, and JCB.
Also displays the Toast
message with the error.
creditCardNumberWithSpacesToast()
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.
Also displays the Toast
message with the error.
creditCardNumberWithDashesToast()
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.
Also displays the Toast
message with the error.
validUrlToast()
Returns true
if the text is a valid URL
Also displays the Toast
message with the error.
regexToast()
Returns true
if the text matches passed RegEx
pattern.
Also displays the Toast
message with the error.
Last updated