Quickly & Easily Validating Your Text with Easy Validation
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. wajahatkarim3/EasyValidation *EasyValidation - :heavy_check_mark: A text and input validation library in Kotlin for Android*github.com
**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 method and higher order functions. In future, more views will be added in this list.
How it works?
Now let’s see what **EasyValidation **can do for us. First, you have to include it in your android projects using Gradle like this:
Now for example, you can validate any email string like this:
Not only String or Text , you can perform these checks on EditText , TextView , AutoCompleteTextView, TextInputLayout, and Spinner like this:
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.
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:
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 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:
Along with 30+ 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.
You can use this rule using Validator.addRule() method like this:
EasyValidation Library and Documentation
You can check the library and it’s code at GitHub at below link. wajahatkarim3/EasyValidation *EasyValidation - :heavy_check_mark: A text and input validation library in Kotlin for Android*github.com
And for the usage and documentation for how to use it, you can check it at GitBook at below link. Introduction - EasyValidation *EasyValidation is a text validation library for Android developed in Kotlin. It supports text validation for , , , , …*wajahatkarim.gitbook.io