Home > widget-integration > FilterValidationHelper > isValidLength

FilterValidationHelper.isValidLength() method

Validates if a string length is within acceptable bounds.

Checks if string length falls between minimum and maximum values (inclusive).

Signature:

isValidLength(value: string, minLength?: number, maxLength?: number): boolean;

Parameters

Parameter

Type

Description

value

string

The string to validate

minLength

number

(Optional) Minimum allowed length (inclusive). Default: 0

maxLength

number

(Optional) Maximum allowed length (inclusive). Default: Infinity

Returns:

boolean

true if the length is within bounds [minLength, maxLength], false otherwise

Example

Validate search term length:

if (!this.validationHelper.isValidLength(searchTerm, 2, 100)) {
  this.showError('Search term must be 2-100 characters');
  return;
}