io.github.ninobomba.commons.validator.EmailValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of t4m-commons Show documentation
Show all versions of t4m-commons Show documentation
Tools 4 Monkeys - Java Commons
The newest version!
package io.github.ninobomba.commons.validator;
import org.apache.commons.lang3.StringUtils;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
/**
* The EmailValidator class is responsible for validating email addresses based on a regular expression.
* It implements the ConstraintValidator interface and provides an isValid method to perform the validation.
*
* The regular expression used for validation ensures that the email address follows the standard email format.
*
*
Example usage:
*
* EmailValidator emailValidator = new EmailValidator();
* boolean isValid = emailValidator.isValid("[email protected]", null);
*
*/
public class EmailValidator implements ConstraintValidator < Email, String > {
private static final String REGEX =
"^[\\w!#$%&'*+/=?`{|}~^-]+(?:\\.[\\w!#$%&'*+/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$";
@Override
public boolean isValid ( String value, ConstraintValidatorContext context ) {
if ( StringUtils.isBlank ( value ) ) return false;
return value.matches ( REGEX );
}
}