Quickly & Easily Validating Your Text with Easy Validation
Tags: android, kotlin, opensource, library
Published: 2018-10-14 08:00:02

---
title: Quickly & Easily Validating Your Text with Easy Validation
published: true
description: A text and input validation library for Android utilizing powerful features of Kotlin
tags: android, kotlin, open source, library
---

> Originally posted on my [Medium profile](https://medium.com/@wajahatkarim3)


![](https://cdn-images-1.medium.com/max/8334/1*kPR2nkCyTMj3p-kQvr5i2w.jpeg)

In this data-driven era of technology, almost all websites and apps have one thing in common. That’s text validation for their data input forms and pages. This task of validating input and text before calling web services and APIs have become a routine for developers.

In Android, this sometimes become too complex and tedious to perform validations and checks on multiple EditText and TextInputLayout views. Specially, when it comes to perform multiple checks to make sure that your user’s password is unbreakable and complex. These kinds of tasks often becomes boring for android developers and can cause major security vulnerabilities if not managed properly.

I was also frustrated in this situation and after searching through Internet and GitHub and using various third-party libraries, I have come up with this easy validation library surprisingly called as [**EasyValidation**](https://github.com/wajahatkarim3/EasyValidation)

**EasyValidation** is an android library developed in Kotlin to provide an easy-to-use way to perform validation checks on any Text input through any `String` , `EditText`, `TextView`, `AutoCompleteTextView`, `TextInputLayout`, and `Spinner` using the power of Kotlin Extension methods and higher order functions. In future, more views will be added in this list.

## How it works?

Now let’s see what [**EasyValidation**](https://github.com/wajahatkarim3/EasyValidation) can do for us. First, you have to include it in your android projects using Gradle like this:

![](https://cdn-images-1.medium.com/max/3754/1*aRMyI9XnYKaBfXgZpA3wDA.png)

Now for example, you can validate any email string like this:

![](https://cdn-images-1.medium.com/max/3604/1*iDkLn0wRged3czeJXoXLlw.png)

Not only `String` or `Text` , you can perform these checks on `EditText`, `TextView`, `AutoCompleteTextView`, `TextInputLayout`, and `Spinner` like this:

![](https://cdn-images-1.medium.com/max/3610/1*RuOgaINO2akjJPYCGaMfQA.png)

There are around 30+ built-in rules in the **core module library** such as email, empty, number, credit card number etc. You can check all these in [Rules page](https://wajahatkarim.gitbook.io/easyvalidation/usage/built-in-rules).

You can also apply multiple checks to make complex input very easily. For example, you want user’s password to have at least 8 characters length with one special character, one uppercase letter and one number. Then you can do these types of checks like this:

![](https://cdn-images-1.medium.com/max/3604/1*KSPtH4BXLkkaz1C1DxoI1w.png)

You can see how easy is to perform multiple validation checks. One thing to note here is the check() method. When you perform multiple validations, you will have to manually call check() method in order to start validations. In single validation, this method is called automatically.

You can not only [perform multiple validations](https://wajahatkarim.gitbook.io/easyvalidation/usage/multiple-validation-checks) on same text, but you can also perform same validation on multiple text streams at same time by using [Collection Extensions](https://wajahatkarim.gitbook.io/easyvalidation/usage/collection-extensions#list-of-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:

![](https://cdn-images-1.medium.com/max/3604/1*1VqErK1zahknemrvE2BqvA.png)

Along with [30+ built-in rules](https://wajahatkarim.gitbook.io/easyvalidation/usage/built-in-rules), you can create your own custom rules very easily.

First step is you have to create your `Rule` class by extending `BaseRule` or any other existing rule like this.

![](https://cdn-images-1.medium.com/max/3594/1*z9q-PZ4i-Do4uZLS6R8ApQ.png)

You can use this rule using `Validator#addRule()` method like this:

![](https://cdn-images-1.medium.com/max/3604/1*RDPjkn9NtFdXO8bu8ecaqQ.png)

## EasyValidation Library and Documentation

You can check the library and it’s code at GitHub at below link.
[**EasyValidation**](https://github.com/wajahatkarim3/EasyValidation)

{% github wajahatkarim3/EasyValidation %}

And for the usage and documentation for how to use it, you can check it at GitBook at below link.
[**Documentation**](https://wajahatkarim.gitbook.io/easyvalidation/)

...

**Wajahat Karim** is a graduate from NUST, Islamabad, an experienced mobile developer, an active open source contributor, and co-author of two books [Learning Android Intents](https://www.amazon.com/Learning-Android-Intents-Muhammad-Usama/dp/1783289635) and [Mastering Android Game Development with Unity](https://www.amazon.com/Mastering-Android-Game-Development-Unity/dp/1783550775/). In his spare time, he likes to spend time with his family, do experiments on coding, loves to write about lots of things (mostly on blog and medium) and is passionate contributor to open source. In June 2018, one of his library became #1 on [Github Trending](https://github.com/trending). [His libraries](http://github.com/wajahatkarim3) have about 2000 stars on Github and are being used in various apps by the developers all around the globe. Follow him on [Twitter](https://twitter.com/WajahatKarim) and [Medium](https://medium.com/@wajahatkarim3) to get more updates about his work in Writing, Android and Open Source.