Skip to content

InputMask

<ax-input-mask> formats input against a mask pattern and stores the masked text as its value (ControlValueAccessor over string). The masking is a pure, tested applyMask(raw, mask) engine.

import { AxInputMaskComponent, applyMask } from '@axisui-ng/forms';
<ax-input-mask mask="(999) 999-9999" [(value)]="phone" ariaLabel="Phone" />
<ax-input-mask mask="99/99/9999" placeholder="MM/DD/YYYY" [(value)]="dob" ariaLabel="Date of birth" />
<ax-input-mask mask="9999 9999 9999 9999" [(value)]="card" ariaLabel="Card number" />
<ax-input-mask mask="AAA-9999" [(value)]="plate" ariaLabel="License plate" />
TokenMatches
9a digit (0–9)
Aa letter (a–z / A–Z)
*alphanumeric

Any other character in the mask is a literal (emitted verbatim; a matching typed literal is consumed).

OptionValuesDefaultNotes
size'sm' | 'md' | 'lg''md'Shared with ax-input (inputVariants).
<ax-input-mask mask="(999) 999-9999" size="lg" [(value)]="phone" ariaLabel="Phone" />
InputTypeDefaultNotes
maskstring''Pattern (empty = no masking).
valuemodel<string | null>nullThe masked text; two-way + CVA.
placeholderstring''Placeholder text.
size'sm' | 'md' | 'lg''md'Control height/padding.
disabledbooleanfalseAlso set by setDisabledState.
readonlybooleanfalseRead-only.
invalidbooleanfalseError styling + aria-invalid.
describedBystring | nullnullaria-describedby.
ariaLabelstring''Accessible name.

The field reflects the masked text on every keystroke (rejected characters are dropped). The caret is restored from the masked prefix before the previous caret, so mid-string edits and backspace do not jump to the end.

Renders a native <input>. Provide ariaLabel and/or pair with a FormField label; use describedBy for helper/error text and invalid for error styling + aria-invalid.

Interactive examples live in Storybook under Forms / InputMask. Run pnpm storybook to explore them.