Tuesday, 9 June 2015

Validate an email address using regular expression in android


  Here I am going to explain how to validate an E-mail address using Regular    Expressions

  String Name="dhinakaran.cool@gmail.com";

  String EmailPattern = "^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]{1}|[\\w-]{2,}))@"
+ "((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
+ "[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\."
+ "([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
+ "[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
+ "([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$";

   if (Name.matches(EmailPattern))
{
    Toast.makeText(activity, Valid, Toast.LENGTH_SHORT).show();

}
else
{
Toast.makeText(activity, InValid, Toast.LENGTH_SHORT).show();
}



Happy Coding:)