Input Validator – Android Library

Over the weekend I have been working on a small library to help validating the input into form fields in Android. I have open sourced it on Github and I am in the process of deploying it to Maven.


This library was born from some self-inflicted validation frustration in a project at work and jealousy at one of my colleagues better solution in the iOS department.

What does it do?

The library provides a class named InputValidator that can be wrapped around any object that extends from TextView. The InputValidator will validate the value of the input against a set of Validators attached to it. The InputValidator sets an OnFocusListener that validates the input when the user leaves the input and it uses a TextWatcher to remove the error when the user has started typing again.

The Validator is a simple interface with two methods. The first is boolean validate(String) this is where any validation logic will happen and will return true if the input is valid and false if it is invalid. The second method if String getValidationMessage() which returns a message to display if there has been a validation error.

A basic jQuery plugin

jQuery is an extremely popular Javascript library that simplifies cross-browser Javascript into an easy to use API. As of May 2014, 50.1% of the top 1 million websites use jQuery in one for or another to help enhance their websites. For the same month 66.8% of the top 100,000 website and 78.5% of the top 10,000 websites use jQuery. Those stats can be found here. The popularity of the jQuery library means that as a developer you will likely encounter and work with jQuery.

You can develop with jQuery the same as if it were any bit of Javascript: write your code in an external .js file and include it onto your webpage. However, jQuery allows you to create plugins that extend jQuery and therefore can be reused through out a number of websites. jQuery plugins should be modular; it does one thing and one thing only. Similar to how a class in any programming language or CSS should only do one thing, creating reusable code.

To give you a head start with developing jQuery plugins below is a small template that you can use to build your jQuery plugin around.

The above is a compilation of these two tutorials provided on the jQuery website:

Relevant links: