Input validation can be painful. Building forms in any technology is a boring and tedious job, yet it’s one of the most common tasks in app development.

When implementing form validation, we typically face three critical concerns:

  1. In-depth data validation - Ensuring the data format is correct
  2. Mandatory fields checking - Making sure required fields aren’t empty
  3. Error presentation - Showing users what went wrong

Introducing FormEditText

To solve these pain points, I created an open-source library called FormEditText, available on GitHub.

The library enables developers to validate EditText fields through simple XML attributes, eliminating boilerplate validation code.

Basic Usage

First, define a custom namespace in your layout and add validation attributes:

<com.andreabaccega.widget.FormEditText
    android:id="@+id/email"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textEmailAddress"
    app:testType="email"
    app:emptyAllowed="false" />

Validation Behavior

When you call validate() on a FormEditText:

  • Valid input: Returns true without additional action
  • Invalid input: Returns false and automatically displays an error message

Built-in Validators

The library includes validators for:

  • Email addresses
  • Phone numbers
  • Credit cards
  • IP addresses
  • Web URLs
  • Custom regex patterns
  • And more…

Try It Out

The library has grown to over 1,400 stars on GitHub and continues to help Android developers build better forms.