Email Id Validation in android

Email id validation in front end in app is very common things in android  . Here is the code to check email id in android .


import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class EmailValidator {
private Pattern pattern;
private Matcher matcher;

private static final String EMAIL_PATTERN =
"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

public EmailValidator() {
pattern = Pattern.compile(EMAIL_PATTERN);
}

public boolean validate(final String hex) {

matcher = pattern.matcher(hex);
return matcher.matches();

  }
}



// for  activity 

if(new EmailValidator().validate(etEmail.getText().toString())==false)
{
   // write code for not valid
}
else
{
  // write code for valid
}


Find Us : 
        Facebook : @apnaandroid
        Google+   : Apna Java
        Youtube : Android & Java Tutorial

Comments

Popular posts from this blog

Custom Calendar in android

Disable/Hide Year from DatePickerDialog in android

Coordinator Layout in Android