Skip to content

Instantly share code, notes, and snippets.

@sachin-handiekar
Created June 16, 2011 14:53
Show Gist options
  • Save sachin-handiekar/1029395 to your computer and use it in GitHub Desktop.
Save sachin-handiekar/1029395 to your computer and use it in GitHub Desktop.
Email Validator
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EmailValidator {
public boolean isValidEmailAddress(String emailAddress) {
String expression = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
CharSequence inputStr = emailAddress;
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
return matcher.matches();
}
}
@sachin-handiekar
Copy link
Author

A simple emailValidator method for copy n paste

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment