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 Details

    • 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 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 Details

    • 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 validate

      context - the value context for validation

      Returns:

      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

    • toString

      public String toString()

      Overrides:

      toString in class Object