Android TutorialsNo Comments

297 views.

In this tutorial, we will learn about Android Form Validation. In any app input validation is a very important thing to do. Input Validation eliminates the errors that can be done by user while giving inputs to our app. For example if we want to get the user’s email we can check the entered email is a valid email or not before storing it inside the database. So lets start our Android Form Validation tutorial.

in gradle need to and below dependency

Mainactivity.java

Strings.xml

What we did?

  • First we defined an AwesomeValidation object.
  • We initialized the object with BASIC style, we have two more different style COLORATION and UNDERLABEL.
  • Then we added the validation to required EditTexts using addValidation() method with AwesomeValidation object.
  • addValidation() : This method takes 4 arguments.
  • Activity Context, we used this to pass the current activity context.
  • Resource id of EditText in which we want to add validation, we used R.id.viewid
  • Regex String for adding validation, you can use Regex for more kind of validations
  • String resource id for error message to show the error if validation fails
  • Then in submitForm() method we are validating the inputs with validate() method. The method returns true or false, true if validation succeeds and false if validation fails.

Testing the App
Now you can run the app to test whether it is working or not.

Android-Form-Validation-Example

 

Be the first to post a comment.

Add a comment