Class StringLengthValidator

  • All Implemented Interfaces:
    Validator<java.lang.String>, java.io.Serializable, java.util.function.BiFunction<java.lang.String,​ValueContext,​ValidationResult>

    public class StringLengthValidator
    extends AbstractValidator<java.lang.String>
    Verifies that the length of a string is within the given range.
    Since:
    8.0
    Author:
    Vaadin Ltd.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      StringLengthValidator​(java.lang.String errorMessage, java.lang.Integer minLength, java.lang.Integer maxLength)
      Creates a new StringLengthValidator with a given error message and minimum and maximum length limits.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ValidationResult apply​(java.lang.String value, ValueContext context)
      Validates the given value.
      java.lang.Integer getMaxLength()
      Gets the maximum permissible length of the string.
      java.lang.Integer getMinLength()
      Gets the minimum permissible length of the string.
      void setMaxLength​(java.lang.Integer maxLength)
      Sets the maximum permissible length of the string.
      void setMinLength​(java.lang.Integer minLength)
      Sets the minimum permissible length.
      java.lang.String toString()  
      • 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​(java.lang.String errorMessage,
                                     java.lang.Integer minLength,
                                     java.lang.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 fails
        minLength - 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​(java.lang.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 validate
        context - the value context for validation
        Returns:
        the validation result
      • getMaxLength

        public java.lang.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 java.lang.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​(java.lang.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​(java.lang.Integer minLength)
        Sets the minimum permissible length.
        Parameters:
        minLength - the minimum length to accept or null for no limit
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object