Registration Form Validation in Android

Registration form validation android – Here, I share with you how to validate the registration form in android. Actually this is the simple way to validate the form in android. The same way we have used to validate form like PHP, JAVA, etc. So you have easily make an registration form validation android.

Every web and mobile application need registration form and login form for store the user details. So here we are developing this methods with lot of features like validation, material design animation, responsive design and more. This code surely helps to create perfect android registration (sign up & Login form) using Java in android Studio platform.

Cloud Firebase is one of the best ways for store our files. Alternatively you can also use MySQL & SQLite database when you have no idea about Firebase database. But most of companies are currently using & hire Firebase developers. The reason is it’s best for develop large scale web applications.

registration form validation android

Nowadays most peoples are like to use mobile application so everyone some awareness to develop mobile application like form validation, email alert and much more. But you have some knowledge in Java to develop the mobile application. In previous tutorial i have explain how to convert website to android application. So you have website? & convert mobile application? just read this tutorial Convert Website to Android Application

Registration form validation Android

Okay let’s start our tutorial, First you have create new project and the project name is Form Validation. Then click Next, Like (below image).
registration form validation android

Then the activity menu’s displayed. Now you have choose Empty Activity, then click Next, Finish (Like below image)
.

registration form validation android

Now, we have validate entire form which fields for we used in our project. Open activity_main.xml then create some of the input fields in the form

I have create four fields in the form they are, Name, Email, Password & Mobile number.

form validation android

Create Registration Form

First, you have to create some fields in the form to validate the registration form. Open activity_main.xml and copy the below code. I have create 4 fields in the form. Its look like,

form validation android

MainActivity.java

Then move on the main page of MainActivity.java file. Hereafter copy the below code and paste your MainActivity.java file. You can also download the entire source code in end of the article. For the clarification here we are adding those code. The code is,

package com.example.vetri.formvalidarion;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.basgeekball.awesomevalidation.AwesomeValidation;
import com.basgeekball.awesomevalidation.ValidationStyle;
import com.google.common.collect.Range;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    //The view objects
    private EditText editTextName, editTextEmail, editTextMobile,
            editTextPassword;

    private Button buttonSubmit;

    //defining AwesomeValidation object
    private AwesomeValidation awesomeValidation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //initializing awesomevalidation object
        /*
        * The library provides 3 types of validation
        * BASIC
        * COLORATION
        * UNDERLABEL
        * */
        awesomeValidation = new AwesomeValidation(ValidationStyle.BASIC);

        //initializing view objects
        editTextName = (EditText) findViewById(R.id.editTextName);
        editTextEmail = (EditText) findViewById(R.id.editTextEmail);
        editTextPassword = (EditText) findViewById(R.id.editTextPassword);
        editTextMobile = (EditText) findViewById(R.id.editTextMobile);

        buttonSubmit = (Button) findViewById(R.id.buttonSubmit);


        //adding validation to edittexts
        awesomeValidation.addValidation(this, R.id.editTextName, "^[A-Za-z\\s]{1,}[\\.]{0,1}[A-Za-z\\s]{0,}$", R.string.nameerror);
        awesomeValidation.addValidation(this, R.id.editTextEmail, Patterns.EMAIL_ADDRESS, R.string.emailerror);
        awesomeValidation.addValidation(this, R.id.editTextPassword, "^[A-Za-z\\s]{1,}[\\.]{0,1}[A-Za-z\\s]{0,}$", R.string.passworderror);
        awesomeValidation.addValidation(this, R.id.editTextMobile, "^[2-9]{2}[0-9]{8}$", R.string.mobileerror);


        buttonSubmit.setOnClickListener(this);
    }

    private void submitForm() {
        //first validate the form then move ahead
        //if this becomes true that means validation is successfull
        if (awesomeValidation.validate()) {
            Toast.makeText(this, "Registration Successfull", Toast.LENGTH_LONG).show();

            //process the data further
        }
    }

    @Override
    public void onClick(View view) {
        if (view == buttonSubmit) {
            submitForm();
        }
    }
}

Its look like,

form validation android

Define the Validation Error Message

Here, we have define validation error message in strings.xml. Open strings.xml file and copy the below code,

The code is,

    Form Validation
    Enter Valid Name
    Enter Valid Email
    Enter Some Password
    Enter Valid Mobile Number

Its look like,

form validation android

Add Validation Library in Gradle file

We need validation library to validate to registration form. So here we have add Gradle library file in build.gradle. Add the below code,

compile 'com.basgeekball:awesome-validation:1.3'

Its look like,

form validation android

Finally all procedure is completed. Now time to execute the application.

Executing the Application

Now, you have execute your android application in android emulator. If you are facing any issues during the development time, just contact us for more doubts. We are always online to help our blog readers. Finally the application looks like,

registration form validation android

That’s all..If you are struggle to validate your form, feel free ask me in below comment. Wants to read more our popular post for earn more money from the trusted websites? This is for you, because nowadays most of working professionals are make money via part time jobs.

Leave a Reply