Skip to content

@jsvision/ui / Validator

Interface: Validator ​

Defined in: ui/src/controls/validators/types.ts:15

A rule that constrains what an Input accepts. Attach one via the Input's validator option.

A validator has two gates that fire at different moments:

  • isValidInput runs live on every keystroke and must accept partial values that are still being typed (e.g. "12" while typing an age). Rejecting here blocks the keystroke.
  • isValid runs once the user leaves the field (or when you call Input.valid()) and checks the complete value. Failing here does not trap focus — it flags the field as invalid so you can show feedback.

Use the built-in factories (filter, range, lookup, picture) or implement this shape yourself for a custom rule.

Properties ​

error? ​

readonly optional error?: string

Defined in: ui/src/controls/validators/types.ts:28

Optional message describing the invalid state, for you to surface to the user.

Methods ​

fill()? ​

optional fill(s): string

Defined in: ui/src/controls/validators/types.ts:26

Optional post-keystroke rewrite. After accepting a keystroke, Input calls this and stores the returned string, letting a validator auto-insert formatting (e.g. 123 → 123- for a ###-## mask) or apply case transforms (abc → ABC). Return s unchanged when nothing applies. Only picture implements it; the other validators omit it. Never throws.

Parameters ​

s ​

string

Returns ​

string


isValid() ​

isValid(s): boolean

Defined in: ui/src/controls/validators/types.ts:19

Blocking gate run on completion / focus-leave: is the finished value acceptable?

Parameters ​

s ​

string

Returns ​

boolean


isValidInput() ​

isValidInput(s): boolean

Defined in: ui/src/controls/validators/types.ts:17

Live per-keystroke gate: may this string exist mid-edit? Must accept partial input.

Parameters ​

s ​

string

Returns ​

boolean