Skip to content

@jsvision/ui / filter

Function: filter()

filter(chars): Validator

Defined in: ui/src/controls/validators/filter.ts:24

Build a filter validator over an allowed-character set.

Parameters

chars

string

The allowed characters, as a literal list or a compact range spec — X-Y expands to an inclusive range (e.g. '0-9', 'A-Za-z ', 'A-Fa-f0-9'). Passing '' rejects all non-empty input.

Returns

Validator

A Validator that accepts only values whose characters are all in the set.

Example

ts
import { signal } from '@jsvision/ui';
import { Input, filter } from '@jsvision/ui';

const name = signal('');
// Letters and spaces only — digits/punctuation are rejected as you type.
const input = new Input({ value: name, validator: filter('A-Za-z ') });