Top Description Fields Constructors Methods
org.hibernate.validator.internal.constraintvalidators

public Class AbstractEmailValidator<A extends java.lang.annotation.Annotation>

extends Object
implements ConstraintValidator<A extends Annotation, CharSequence>
Class Inheritance
All Implemented Interfaces
jakarta.validation.ConstraintValidator
Known Direct Subclasses
org.hibernate.validator.internal.constraintvalidators.bv.EmailValidator, org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator
Static Imports
java.util.regex.Pattern.CASE_INSENSITIVE

Checks that a given character sequence (e.g. string) is a well-formed email address.

The specification of a valid email can be found in RFC 2822 and one can come up with a regular expression matching all valid email addresses as per specification. However, as this article discusses it is not necessarily practical to implement a 100% compliant email validator. This implementation is a trade-off trying to match most email while ignoring for example emails with double quotes or comments.

Authors
Emmanuel Bernard, Hardy Ferentschik, Guillaume Smet

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
private static final Pattern
LOCAL_PART_PATTERN

Regular expression for the local part of an email address (everything before '@')

private static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
isValid(CharSequence
object to validate
value
,
ConstraintValidatorContext
context in which the constraint is evaluated
context
)

Implements jakarta.validation.ConstraintValidator.isValid.

Implements the validation logic.
private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOCAL_PART_ATOMback to summary
private static final String LOCAL_PART_ATOM
LOCAL_PART_INSIDE_QUOTES_ATOMback to summary
private static final String LOCAL_PART_INSIDE_QUOTES_ATOM
LOCAL_PART_PATTERNback to summary
private static final Pattern LOCAL_PART_PATTERN

Regular expression for the local part of an email address (everything before '@')

MAX_LOCAL_PART_LENGTHback to summary
private static final int MAX_LOCAL_PART_LENGTH

Constructor Detail

AbstractEmailValidatorback to summary
public AbstractEmailValidator()

Method Detail

isValidback to summary
public boolean isValid(CharSequence value, ConstraintValidatorContext context)

Implements jakarta.validation.ConstraintValidator.isValid.

Doc from jakarta.validation.ConstraintValidator.isValid.

Implements the validation logic. The state of value must not be altered.

This method can be accessed concurrently, thread-safety must be ensured by the implementation.

Parameters
value:CharSequence

object to validate

context:ConstraintValidatorContext

context in which the constraint is evaluated

Returns:boolean

false if value does not pass the constraint

Annotations
@Override
isValidEmailLocalPartback to summary
private boolean isValidEmailLocalPart(String localPart)