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-mask
Custom Alpine directive that marks the Input Mask Root.
Input
-
x-input-mask:input
Custom Alpine directive that marks the Input Mask.
-
x-mask
Type:
string
This attribute defines the values that the input will accept.
9
allows any number,a
allows any letter,*
allows any character. -
placeholder
Type:
string
The displayed “empty” values of the input. Used to show the Input Mask Mask Placeholder value.
-
pattern
Type:
RegExp
Native form validation attribute.
Take care to ensure this value validates according to your
x-mask
attribute. 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-placeholder
Custom Alpine directive that marks the Input Mask Input Placeholder.
Mask Display
Displays the updated mask value as the user types.
-
x-input-mask:mask-placeholder
Custom 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.