Skip to content

A text and input validation library for Android, provides a simple way to validate input, and handles ui using ValidationEditText.

Notifications You must be signed in to change notification settings

tsuryo/ValidationEditText

Repository files navigation

ValidationEditText

Android library provides a simple way to validate input, and handles ui using ValidationEditText.

ValidationEditText

Prerequisites

Android 5.0+ API 21+

Where to

Features

  • Validate with built in patterns ValidationType
  • Validate with your own custom regex Custom pattern validation.
  • Customizable text size, text color.
  • Customizable backgrounds - all layout, input background.
  • Automatically showing/dismissing error on validation process.
  • Auto parse forms layout xml built with ValidationEditText.

Getting familiar

Classes you should be familiar with:

  • ValidationEditText - View that handles validation ui,
    showing error nicely with animations, hints, input, colors, etc.
    Handles validation logic as individual ValidationEditText.
  • EditTextValidator - This class will handle all the validation process,
    such as Parsing your xml, adding ValidationEditTexts,
    executing the actual validation process and more.
  • ValidationEditText attributes

Usage

Simplest way to use

Java

	mValidator = new EditTextValidator(this);
	mValidator.setLayout(this, R.layout.activity_main);

	button.setOnClickListener(new View.OnClickListener() {
	    @Override
	    public void onClick(View v) {
	        mValidator.validate();
	    }
	});

EditTextValidator(ValidationListener listener)

Implement this interface to get notified with the results.

    public interface ValidationListener {
        void onValidated();

        void onFailedToValidate();
    }

EditTextValidator#setLayout(Activity a, int layout)

Param a - Set the hosting Activity.
Param layout - Set the layout contains ValidationEditText resourceId.

EditTextValidator#setLayout(View v, int layout)

Param v - Set the hosting View - for fragments use it in onViewCreated(View view, @Nullable Bundle savedInstanceState)
Param layout - Set the layout contains ValidationEditText resourceId.

EditTextValidator

XML

	<com.tsoft.validationedittext.views.ValidationEditText
	    android:fontFamily="@font/satum"
	    android:hint="@string/enter_email"
	    app:error_text="Enter valid email address"
	    app:input_background="@drawable/vet_bg"
	    app:pattern="EMAIL"
	    app:text_color="@color/colorAccent" />

	<com.tsoft.validationedittext.views.ValidationEditText
	    android:hint="@string/enter_password"
	    app:custom_pattern="@string/pass_regex"
	    app:error_text="Custom error, enter valid"
	    app:input_background="@drawable/vet_bg"/>
Attribute Use to
android:inputType use to set the inputType
android:fontFamily use to set the font
android:hint use to set the hint text
android:text use to set the text
android:textColorHint use to set the hint color
android:textSize use to set the text size
android:background use to set the whole view background
input_background use to set the input background
text_color use to set the input text color
error_text use to set the error text to show on validation failure
et_text use to set the input text
pattern use to set the ValidationType
custom_pattern use to set custom regex pattern

Access this attributes from Java code using ValidationEditText
getters and setters - ValidationEditText

Other ways to use

  • Handle ValidationEditText individually
   ValidationEditText vet = findViewById(R.id.vEt);
   vet.setListener(new ValidationEditText.Listener() {
       @Override
       public void onValidated() {
           
       }

       @Override
       public void onFailure(String msg) {

       }
   });
   vet.validate();
   vet