How add Email Validation in Edittext in Android Application (Example Login Page)


          When we building login page in android, usually user must input two field : email and password, but sometimes user forgot input one of fields and application will show message to tell user "please  add email or password  "
         The question is how create function to validation email? i will tell you how to do that with simple way, easy and fast to learn.

First Step : 

               You create new project application and give name as ValidationEmail , and then you design login page in content_main.xml or in your xml file 
Code content_main.xml : 




and then change your activity_main.xml .
code for activity_main.xml :


 Second Step :
      
         You must create method for check edittext's length because we can't go to proccess login if edittext is empty and create validation email method, its will check email formulation.Remember, email must have a mandatory character such as @ and .com or co.id.i put all method in MainActivity.java.

Code for MainActivity.java


 
 in previous code line, there is getValidText() and  isValidEmailAddress() , each others have different function and action.
  • getValidText to check email and password field is empty or not
  • isValidEmailAddress to check email's characters.
Third Step :

    Running the project and try to add wrong email characters like i input email field "indah" and password "indah", then click button login. after that will show a toast message "email validation is wrong"



 Step is Finish().. very easy right? i hope the tutorial will make your development proccess  more fast.
Thank you and please give a comment


Share this

Related Posts

Previous
Next Post »