Android EditText Validation – Library

Published by Kapil Mohan on

Link: https://github.com/vekexasia/android-edittext-validator

dependencies {
	// ...
	compile 'com.andreabaccega:android-edittext-validator:1.3.5'
	// ...
}
  • Needs to add an extra schema in root layout :
  • whatever:testType can be replaced with options from options tab for validation
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:whatever="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <!-- Some stuff -->

	<com.andreabaccega.widget.FormEditText
           whatever:testType="alpha"
           android:id="@+id/et_firstname"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           />    

    <!-- Some other stuff -->

</LinearLayout>
  • regexp: for custom regexp
  • numeric: for an only numeric field
  • alpha: for an alpha only field
  • alphaNumeric: guess what?
  • email: checks that the field is a valid email
  • creditCard: checks that the field contains a valid credit card using Luhn Algorithm
  • phone: checks that the field contains a valid phone number
  • domainName: checks that field contains a valid domain name
  • ipAddress: checks that the field contains a valid ip address
  • webUrl: checks that the field contains a valid url
  • personName: checks if the entered text is a person first or last name.
  • personFullName: checks if the entered value is a complete full name.
  • date: checks that the field is a valid date/datetime format ( if customFormat is set, checks with customFormat )
  • numericRange: checks that the field is a valid value between integers. (minNumber and maxNumber must be set)
  • floatNumericRange: checks that the field is a valid value between integers (but decimal values are allowed). (minNumber and maxNumber must be set)
  • nocheck: It does not check anything except the emptyness of the field.

You can customize them using the attributes

  • testErrorString used when the field does not pass the test
  • emptyErrorString used when the field is empty
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:whatever="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <!-- Some stuff -->

	<com.andreabaccega.widget.FormEditText
           whatever:testType="alpha"
           whatever:emptyErrorString="@string/your_name_cannot_be_empty"
           whatever:testErrorString="@string/your_name_is_ugly"
           android:id="@+id/et_firstname"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           />    

    <!-- Some other stuff -->

</LinearLayout>

Android EditText Validation library is an extension of editText for providing Validation functionality.

for more details:- https://github.com/vekexasia/android-edittext-validator

Library Details:

  • Language: Java
  • current Version: 1.3.5
  • License: MIT

Kapil Mohan

Like to add color to developers life and apps. Can create smile using Android, iOS, PHP, codeignitor, web technologies, etc... Feel free to contact me at [email protected] .