Package play.data.validation
Class Constraints
java.lang.Object
play.data.validation.Constraints
Defines a set of built-in validation constraints.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceDefines a email constraint for a string field.static classValidator for@Emailfields.static @interfaceDefines a maximum value for a numeric field.static @interfaceDefines a maximum length for a string field.static classValidator for@MaxLengthfields.static classValidator for@Maxfields.static @interfaceDefines a minimum value for a numeric field.static @interfaceDefines a minimum length for a string field.static classValidator for@MinLengthfields.static classValidator for@Minfields.static @interfaceDefines a pattern constraint for a string field.static classValidator for@Patternfields.static interfaceConstraints.PlayConstraintValidator<A extends Annotation,T> static interfacestatic @interfaceDefines a field as required.static classValidator for@Requiredfields.static interfacestatic interfacestatic @interfacestatic @interfaceDefines a custom validator.static classValidator for@ValidatePayloadWithfields.static classstatic classstatic @interfaceDefines a custom validator.static @interfacestatic classValidator for@ValidateWithfields.static classstatic classSuper-type for validators.static classSuper-type for validators with a payload. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondisplayableConstraint(jakarta.validation.metadata.ConstraintDescriptor<?> constraint) Converts a constraint to a human-readable value.displayableConstraint(Set<jakarta.validation.metadata.ConstraintDescriptor<?>> constraints) Converts a set of constraints to human-readable values.displayableConstraint(Set<jakarta.validation.metadata.ConstraintDescriptor<?>> constraints, Annotation[] orderedAnnotations) Converts a set of constraints to human-readable values in guaranteed order.static Constraints.Validator<String>email()Constructs a 'email' validator.static Constraints.Validator<Number>max(long value) Constructs a 'max' validator.static Constraints.Validator<String>maxLength(long value) Constructs a 'maxLength' validator.static Constraints.Validator<Number>min(long value) Constructs a 'min' validator.static Constraints.Validator<String>minLength(long value) Constructs a 'minLength' validator.static Constraints.Validator<String>Constructs a 'pattern' validator.static Constraints.Validator<Object>required()Constructs a 'required' validator.
-
Constructor Details
-
Constraints
public Constraints()
-
-
Method Details
-
displayableConstraint
public static List<F.Tuple<String,List<Object>>> displayableConstraint(Set<jakarta.validation.metadata.ConstraintDescriptor<?>> constraints) Converts a set of constraints to human-readable values. Does not guarantee the order of the returned constraints.This method calls
displayableConstraintunder the hood.- Parameters:
constraints- the set of constraint descriptors.- Returns:
- a list of pairs of tuples assembled from displayableConstraint.
-
displayableConstraint
public static List<F.Tuple<String,List<Object>>> displayableConstraint(Set<jakarta.validation.metadata.ConstraintDescriptor<?>> constraints, Annotation[] orderedAnnotations) Converts a set of constraints to human-readable values in guaranteed order. Only constraints that have an annotation that intersect with theorderedAnnotationsparameter will be considered. The order of the returned constraints corresponds to the order of theorderedAnnotations parameter.- Parameters:
constraints- the set of constraint descriptors.orderedAnnotations- the array of annotations- Returns:
- a list of tuples showing readable constraints.
-
displayableConstraint
public static F.Tuple<String,List<Object>> displayableConstraint(jakarta.validation.metadata.ConstraintDescriptor<?> constraint) Converts a constraint to a human-readable value.- Parameters:
constraint- the constraint descriptor.- Returns:
- A tuple containing the constraint's display name and the constraint attributes.
-
required
Constructs a 'required' validator.- Returns:
- the RequiredValidator
-
min
Constructs a 'min' validator.- Parameters:
value- the minimum value- Returns:
- a validator for number.
-
max
Constructs a 'max' validator.- Parameters:
value- maximum value- Returns:
- a validator using MaxValidator.
-
minLength
Constructs a 'minLength' validator.- Parameters:
value- the minimum length value.- Returns:
- the MinLengthValidator
-
maxLength
Constructs a 'maxLength' validator.- Parameters:
value- the max length- Returns:
- the MaxLengthValidator
-
email
Constructs a 'email' validator.- Returns:
- the EmailValidator
-
pattern
Constructs a 'pattern' validator.- Parameters:
regex- the regular expression to match.- Returns:
- the PatternValidator.
-