Skip to the content

InputMask

InputMask is an Input that formats digits as the user types. In mask, 0 stands for a digit and any other character is a literal. onChange receives the formatted string, not an event, debounced by 250 ms.
Forms

When to use

Use when
  • The value is a fixed-format number: phone, tax ID, postal code, a typed date.
  • You want the formatted string ((11) 91234-5678) as the value.
Avoid when
  • The value is free text or contains letters — use Input; the mask keeps digits only.
  • The value is money — use InputCurrency.
  • The user picks a date — use InputDate.

Usage

<InputMask aria-label="Phone" mask="(00) 00000-0000" onChange={setPhone} />
<InputMask aria-label="Postal code" mask="00000-000" onChange={setPostalCode} />
<InputMask aria-label="Date" mask="00/00/0000" onChange={setDate} />

Non-digits are stripped and the result is cut at the mask length. A new value prop is re-formatted, so a Form reset() or setValue() updates the field. Sizes, states and clearable work as on Input.

In a Form

<Form
  handleSubmit={onSubmit}
  fields={{
    phone: {
      label: 'Phone',
      component: InputMask,
      inputProps: { mask: '(00) 00000-0000', clearable: true },
      validation: z.string().length(15, 'Enter the full number'),
    },
  }}
/>

Accessibility

  • InputMask renders no label: use Field or pass aria-label.
  • Show the expected format in the placeholder or the hint; the mask does not announce it.

Properties

See also