All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.ninobomba.commons.validator.EmailValidator Maven / Gradle / Ivy

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy