com.vaadin.flow.data.validator.
Class StringLengthValidator
- java.lang.Object
-
- com.vaadin.flow.data.validator.AbstractValidator<String>
-
- com.vaadin.flow.data.validator.StringLengthValidator
-
All Implemented Interfaces:
Validator<String>
,Serializable
,BiFunction<String,ValueContext,ValidationResult>
public class StringLengthValidator extends AbstractValidator<String>
Verifies that the length of a string is within the given range.
Since:
1.0.
Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Constructor Description StringLengthValidator(String errorMessage, Integer minLength, Integer maxLength)
Creates a new StringLengthValidator with a given error message and minimum and maximum length limits.
-
Method Summary
All Methods Modifier and Type Method Description ValidationResult
apply(String value, ValueContext context)
Validates the given value.
Integer
getMaxLength()
Gets the maximum permissible length of the string.
Integer
getMinLength()
Gets the minimum permissible length of the string.
void
setMaxLength(Integer maxLength)
Sets the maximum permissible length of the string.
void
setMinLength(Integer minLength)
Sets the minimum permissible length.
String
toString()
-
Methods inherited from class com.vaadin.flow.data.validator.AbstractValidator
getMessage, toResult
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.function.BiFunction
andThen
-
-
-
-
Constructor Detail
-
StringLengthValidator
public StringLengthValidator(String errorMessage, Integer minLength, Integer maxLength)
Creates a new StringLengthValidator with a given error message and minimum and maximum length limits.
Parameters:
errorMessage
- the error message to return if validation failsminLength
- the minimum permissible length of the string or null for no limit.maxLength
- the maximum permissible length of the string or null for no limit.
-
-
Method Detail
-
apply
public ValidationResult apply(String value, ValueContext context)
Description copied from interface:
Validator
Validates the given value. Returns a
ValidationResult
instance representing the outcome of the validation.Parameters:
value
- the input value to validatecontext
- the value context for validationReturns:
the validation result
-
getMaxLength
public Integer getMaxLength()
Gets the maximum permissible length of the string.
Returns:
the maximum length of the string or null if there is no limit
-
getMinLength
public Integer getMinLength()
Gets the minimum permissible length of the string.
Returns:
the minimum length of the string or null if there is no limit
-
setMaxLength
public void setMaxLength(Integer maxLength)
Sets the maximum permissible length of the string.
Parameters:
maxLength
- the maximum length to accept or null for no limit
-
setMinLength
public void setMinLength(Integer minLength)
Sets the minimum permissible length.
Parameters:
minLength
- the minimum length to accept or null for no limit
-
-