7 Mar 2012

Email validation in Android

1.  public static boolean isEmailValid(String email)
       {
              boolean isValid = false;
              String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
              CharSequence inputStr = email;
              Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
              Matcher matcher = pattern.matcher(inputStr);
              if (matcher.matches())
              {
                     isValid = true;
              }
              return isValid;
       }


2. public boolean checkEmailCorrect(String Email)
       {
              String pttn ="[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";
              Pattern p = Pattern.compile(pttn);
              Matcher m = p.matcher(Email);

              if(m.matches())
              {
                     return true;
              }
              return false;
       }

3.  public final static boolean isValidEmail(CharSequence target)
{
if (target == null)
{
return false;
}
else
{
return android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
}
}



More Ref Link:.


I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.

Thank you :)

No comments:

Post a Comment