Input mask
An input mask is a string expression that constrains input to support valid input values.
Example
Mobile
320pxMobile Lg
480pxTablet
640pxDesktop
1024pxComponent API
Root
-
x-input-maskCustom Alpine directive that marks the Input Mask Root.
Input
-
x-input-mask:inputCustom Alpine directive that marks the Input Mask.
-
x-maskType:
stringThis attribute defines the values that the input will accept.
9allows any number,aallows any letter,*allows any character. -
placeholderType:
stringThe displayed “empty” values of the input. Used to show the Input Mask Mask Placeholder value.
-
patternType:
RegExpNative form validation attribute.
Take care to ensure this value validates according to your
x-maskattribute. A mismatch may lead to a confusing user experience where users are unable to submit a form.
Input Display
Matches the value entered in the input. Match the width of the value entered in the input.
-
x-input-mask:input-placeholderCustom Alpine directive that marks the Input Mask Input Placeholder.
Mask Display
Displays the updated mask value as the user types.
-
x-input-mask:mask-placeholderCustom Alpine directive that marks the Input Mask Mask Placeholder.
Progressive Enhancement
Because this component relies on JavaScript, use the native placeholder attribute to define the “mask” value.
Once JavaScript loads, the placeholder attribute will be removed and used as the initial value of the Input Mask Mask Placeholder. If JavaScript doesn’t load, users will see the native placeholder.
Accessibility
Be sure to show an example of the proper expected formatting. While a placeholder can sometimes be a useful affordance, when used alone, it’s not reliable enough to ensure users understand the expected format.
This can be achieved by creating an “input hint” and linking that value to the input via the aria-describedby attribute, as demonstrated in the examples above.