Home > widget-integration > FilterValidationHelper > isAlphanumeric

FilterValidationHelper.isAlphanumeric() method

Validates if a string contains only alphanumeric characters and allowed special chars.

Useful for validating filter keys, handles, product IDs, and other identifiers. Override to support additional character sets for international shops.

Signature:

isAlphanumeric(value: string, allowedChars?: string): boolean;

Parameters

Parameter

Type

Description

value

string

The value to validate. Must contain only a-z, A-Z, 0-9, and allowed special chars.

allowedChars

string

(Optional) Additional characters to allow beyond alphanumeric. Default: '-_'

Returns:

boolean

true if the value matches the pattern, false otherwise

Example 1

Validate product handle:

if (this.validationHelper.isAlphanumeric(handle)) {
  this.fetchProduct(handle);
}

Example 2

Allow custom characters:

const isValid = this.validationHelper.isAlphanumeric(value, '-_./@');

Example 3

Extend for international character support:

window.boostWidgetIntegration.extend('FilterValidationHelper', (FilterValidationHelper) => {
  return class extends FilterValidationHelper {
    isAlphanumeric(value, allowedChars = '-_') {
      // Support Chinese characters for Asian market
      const pattern = new RegExp(`^[a-zA-Z0-9${allowedChars}\u4e00-\u9fa5]+$`);
      return pattern.test(value);
    }
  };
});