Last active
December 17, 2015 05:49
-
-
Save thaniaclair/5561136 to your computer and use it in GitHub Desktop.
Validador de email java.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
import org.apache.commons.lang3.StringUtils; | |
/** | |
* Validador de e-mail. | |
* @author thania | |
*/ | |
public class EmailValidator { | |
private Pattern pattern = null; | |
private Matcher matcher = null; | |
public 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); | |
} | |
/** | |
* Valida o e-mail. | |
* @param email texto com o email. | |
* @return <code>true</code> se válido, <code>false</code> caso contrário. | |
*/ | |
public boolean isValid(final String email) { | |
if (StringUtils.isBlank(email)) return false; | |
matcher = pattern.matcher(email); | |
return matcher.matches(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment