Package 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>
Verifies that the length of a string is within the given range.
- Since:
- 1.0.
- Author:
- Vaadin Ltd
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionStringLengthValidator
(String errorMessage, Integer minLength, Integer maxLength) Creates a new StringLengthValidator with a given error message and minimum and maximum length limits. -
Method Summary
Modifier and TypeMethodDescriptionapply
(String value, ValueContext context) Validates the given value.Gets the maximum permissible length of the string.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.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 Details
-
StringLengthValidator
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 Details
-
apply
Description copied from interface:Validator
Validates the given value. Returns aValidationResult
instance representing the outcome of the validation.- Parameters:
value
- the input value to validatecontext
- the value context for validation- Returns:
- the validation result
-
getMaxLength
Gets the maximum permissible length of the string.- Returns:
- the maximum length of the string or null if there is no limit
-
getMinLength
Gets the minimum permissible length of the string.- Returns:
- the minimum length of the string or null if there is no limit
-
setMaxLength
Sets the maximum permissible length of the string.- Parameters:
maxLength
- the maximum length to accept or null for no limit
-
setMinLength
Sets the minimum permissible length.- Parameters:
minLength
- the minimum length to accept or null for no limit
-
toString
-