Friday, 3 May 2013

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;
       }

More Ref Link:.

No comments:

Post a Comment