Collection Extensions

This section describes how to perform same checks on multiple texts at same time.

Overview

In EasyValidation, you can not only perform multiple validations on same text, but you can also perform same validation on multiple text streams at same time by using Collection Extensions. For example, you are taking a guest invite list of email addresses, and you have to see that all the texts are valid email addresses. Then you can do it like this:

var emailList = listOf("email1@domain.com", "email2@dom.com", "em3@ga.com")

// You can pass any collection via spread operator
var allValid = validEmailList(*emailList, { str, msg ->
    // The str is an invalid text. The msg contains the message here.
})

// Or you can pass any number of arguments directly
var allValid2 = validEmailList("em@gma.com", "te@st.com", "23ss@", { str, msg ->
    // The str is the invalid text. The msg contains the message here.
})

List of Collection Extensions

The Collection extension methods' names are same as the extension methods names followed by List keyword. For example, validEmail() becomes validEmailList() and so on. These methods accept varargs parameter for multiple texts and an error callback method. Here's list of all the collection extension methods.

Method

Description

nonEmptyList()

Returns true if the text is not empty. And returns false if text is empty.

minLengthList()

Returns false if the length of text is less than given minimum length.

maxLengthList()

Returns false if text length is greater than given length

validEmailList()

Returns true if text is a valid email address.

validNumberList()

Returns true if the text is any valid number

greaterThanList()

Returns false if the text is number less than the given target number

greaterThanOrEqualList()

Returns false if the text is number less than or equal to the given target number

lessThanList()

Returns false if the text is number greater than the given target number

lessThanOrEqaulList()

Returns false if the text is number greater than or equal to the given target number

numberEqualToList()

Returns false if the text is a valid number and equal to the given target number

allUperCaseList()

Returns false if at least one or more characters are lower case

allLowerCaseList()

Returns false if at least one or more characters are upper case

atleastOneUperCaseList()

Returns true if at least one or more characters are upper case

atleastOneLowerCaseList()

Returns true if at least one or more characters are lower case

atleastOneNumberList()

Returns true if at least one or more characters are numbers

startWithNumberList()

Returns true if text starts with any number

startWithNonNumberList()

Returns false if text starts with any number

noNumbersList()

Returns false if the text any number or digit.

onlyNumbersList()

Returns false if text contains any alphabetic character

noSpecialCharactersList()

Returns true if text contain no special characters

atleastOneSpecialCharactersList()

Returns true if text contain at least one special characters

textEqaulToList()

Returns false if the text is not equal to the given text

textNotEqualToList()

Returns true if the text is not equal to the given text

startsWithList()

Returns true if the text starts with the given text

endsWithList()

Returns true if the text ends with the given text

containsList()

Returns true if the text contains the given text

notContainsList()

Returns false if the text contains the given text

creditCardNumberList()

Returns true if the text is valid credit card number. This supports Visa, Master Card, American Express, Diners Club, Discover, and JCB.

creditCardNumberWithSpacesList()

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.

creditCardNumberWithDashesList()

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.

validUrlList()

Returns true if the text is a valid URL

regexList()

Returns true if the text matches passed RegEx pattern.

Last updated