> For the complete documentation index, see [llms.txt](https://wajahatkarim.gitbook.io/easyvalidation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wajahatkarim.gitbook.io/easyvalidation/usage/validation-using-extension-methods.md).

# Extension Methods

### **Overview**

**EasyValidation** utilizes the power of Kotlin Extension methods and provides you huge number of [built-in validation rules](https://wajahatkarim.gitbook.io/easyvalidation/usage/built-in-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:

```kotlin
var txtEmail = findViewById<EditText>(R.id.txtEmail)

// Valid email check
txtName.validEmail() { msg ->
    // Invalid email
    txtName.error = msg
}

// Minimum length check
txtName.minLength(5) {
    txtName.error = it
}
```

### 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                                                                                                                                    |
| `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.                                                                                                                  |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://wajahatkarim.gitbook.io/easyvalidation/usage/validation-using-extension-methods.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
