Masked Input
Text field that types a mask's literals for you, for dates, card numbers, phone numbers and license keys. `value` holds only the raw characters.
<arc-masked-input>Overview
Masked Input is a single-line text field for values with a fixed shape. The mask prop describes the shape with four slot characters: # for a digit, A for a letter (lowercase input is uppercased), a for any letter, and * for a letter or digit. Every other character is a literal the field types for you. With a mask of ##/##/####, the user types eight digits, the slashes appear on their own, and the caret always lands on the next position that takes a character.
value holds only the raw characters. A completed date field reports 12042026, and that's also what it submits with a form. The formatted 12/04/2026 is in the read-only formattedValue and in the formatted key of every event detail.
Typing inserts at the caret and skips past literals. Backspace deletes the previous typed character, skipping literals backward. Pasting drops characters that don't fit and fills the remaining positions, so a card number pasted with dashes lands in a space-grouped mask. A character that doesn't fit its slot is rejected and the caret stays put. Before typing starts, the native placeholder shows the mask shape. After that, the unfilled rest shows in the field as a muted hint, such as 12/__/____.
arc-input fires on each accepted edit. arc-change fires on blur or Enter when the value changed, and as soon as the last position fills, the same way Pin Input commits. A required empty field fails validation with valueMissing, and a partly filled one fails with an "Incomplete value" pattern error, so a half-typed card number can't pass a form's validation.
Guidelines
Do
- Use a mask when the value has one fixed shape: dates, card numbers, phone numbers in a single locale, license or serial keys
- Store `value` and use `formattedValue` only for display
- Listen for `arc-change` to validate or submit. It fires when the mask completes, so the user doesn't have to leave the field
- Set `autocomplete` to the matching token, such as `cc-number` on a card field, so browser autofill keeps working
- Always set a `label`. The mask shape in the placeholder is a hint, not a name for the field
- Use `A` over `a` for license and product keys, so the stored value is always uppercase
Don't
- Don't mask free-form values like names, email addresses or search queries. Use Input
- Don't use it for short verification codes. Pin Input gives each character its own box and advances on its own
- Don't mask international phone numbers with one pattern. Lengths vary by country, and a wrong mask stops people entering their own number
- Don't treat the mask as validation. `##/##/####` accepts 99/99/9999, so check that a date is real before accepting it
Features
- `placeholder-char` sets the hint character, `_` by default
- A mask made only of `#` slots sets `inputmode="numeric"`, so phones show the number keyboard
- Prefix and suffix slots, label, sizes, and disabled and readonly states work as they do on Input
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<!-- Date, card, and license-key masks -->
<div style="display:flex; flex-direction:column; width:100%; max-width:400px; gap:16px;">
<arc-masked-input label="Expiry date" name="expiry" mask="##/##/####" autocomplete="cc-exp"></arc-masked-input>
<arc-masked-input label="Card number" name="card" mask="#### #### #### ####" autocomplete="cc-number"></arc-masked-input>
<arc-masked-input label="License key" name="license" mask="AAA-###-AAA" placeholder-char="•"></arc-masked-input>
</div>
<script>
const card = document.querySelector('[name="card"]');
card.addEventListener('arc-change', (e) => {
// e.detail.value is the raw digits; e.detail.formatted is presentation.
console.log(e.detail.value, e.detail.formatted);
});
</script>import { MaskedInput } from '@arclux/arc-ui-react';
export default function Example() {
return (
<div style={{ display: 'flex', flexDirection: 'column', width: '100%', maxWidth: 400, gap: 16 }}>
<MaskedInput label="Expiry date" name="expiry" mask="##/##/####" autocomplete="cc-exp" />
<MaskedInput
label="Card number"
name="card"
mask="#### #### #### ####"
autocomplete="cc-number"
onArcChange={(e) => console.log(e.detail.value)}
/>
<MaskedInput label="License key" name="license" mask="AAA-###-AAA" placeholder-char="•" />
</div>
);
}<script setup>
import { MaskedInput } from '@arclux/arc-ui-vue';
</script>
<template>
<div style="display:flex; flex-direction:column; width:100%; max-width:400px; gap:16px;">
<MaskedInput label="Expiry date" name="expiry" mask="##/##/####" autocomplete="cc-exp" />
<MaskedInput label="Card number" name="card" mask="#### #### #### ####" autocomplete="cc-number" />
<MaskedInput label="License key" name="license" mask="AAA-###-AAA" placeholder-char="•" />
</div>
</template><script>
import { MaskedInput } from '@arclux/arc-ui-svelte';
</script>
<div style="display:flex; flex-direction:column; width:100%; max-width:400px; gap:16px;">
<MaskedInput label="Expiry date" name="expiry" mask="##/##/####" autocomplete="cc-exp" />
<MaskedInput label="Card number" name="card" mask="#### #### #### ####" autocomplete="cc-number" />
<MaskedInput label="License key" name="license" mask="AAA-###-AAA" placeholder-char="•" />
</div>import { Component } from '@angular/core';
import { MaskedInput } from '@arclux/arc-ui-angular';
@Component({
imports: [MaskedInput],
template: `
<div style="display:flex; flex-direction:column; width:100%; max-width:400px; gap:16px;">
<arc-masked-input label="Expiry date" name="expiry" mask="##/##/####" autocomplete="cc-exp"></arc-masked-input>
<arc-masked-input label="Card number" name="card" mask="#### #### #### ####" autocomplete="cc-number"></arc-masked-input>
<arc-masked-input label="License key" name="license" mask="AAA-###-AAA" placeholder-char="•"></arc-masked-input>
</div>
`,
})
export class PaymentFormComponent {}import { MaskedInput } from '@arclux/arc-ui-solid';
export default function Example() {
return (
<div style={{ display: 'flex', 'flex-direction': 'column', width: '100%', 'max-width': '400px', gap: '16px' }}>
<MaskedInput label="Expiry date" name="expiry" mask="##/##/####" autocomplete="cc-exp" />
<MaskedInput label="Card number" name="card" mask="#### #### #### ####" autocomplete="cc-number" />
<MaskedInput label="License key" name="license" mask="AAA-###-AAA" placeholder-char="•" />
</div>
);
}import { MaskedInput } from '@arclux/arc-ui-preact';
export default function Example() {
return (
<div style={{ display: 'flex', flexDirection: 'column', width: '100%', maxWidth: 400, gap: 16 }}>
<MaskedInput label="Expiry date" name="expiry" mask="##/##/####" autocomplete="cc-exp" />
<MaskedInput label="Card number" name="card" mask="#### #### #### ####" autocomplete="cc-number" />
<MaskedInput label="License key" name="license" mask="AAA-###-AAA" placeholder-char="•" />
</div>
);
}API
autoValidatesbooleanfalse- Runs its own constraint logic and owns the whole validity flag set.
formattedValue- The formatted presentation string: raw characters interleaved with mask literals, e.g. raw 12042026 under a date mask reads 12/04/2026. Read-only: it is derived from value and mask, never stored, and never submitted.
maskstring''- The mask pattern.
#accepts a digit,Aan uppercase letter (lowercase input is uppercased),aany letter,*a letter or digit; every other character is a literal typed for the user. Examples:##/##/####,#### #### #### ####,AAA-###. valuestring''- The RAW accepted characters only, with no mask literals:
12042026, never12/04/2026. The formatted string is presentation; read it fromformattedValue. Programmatic values are conformed against the mask, so setting a formatted string keeps only the characters the mask accepts. placeholder-charstring'_'- Character rendered in unfilled positions of the in-field hint once typing starts (for example
12/__/____). Before any input, the native placeholder shows the full mask shape. Defaults to_. labelstring''- Visible label rendered above the field. Automatically associated with the field via a generated id, ensuring screen readers announce it correctly.
namestring''- The
nameattribute sent with form data on submission. The submitted value is the RAW value, without mask literals. disabledbooleanfalse- Prevents user interaction and applies a muted visual treatment. The field value is excluded from form submission when disabled.
autocompletestring''- Passed through to the inner input, e.g.
cc-numberon a card field so browser autofill can offer saved cards. errorstring''- Error message displayed below the input. When set, the input border turns red and the error text appears.
requiredbooleanfalse- Marks the field as required. An empty field fails validation with valueMissing; a partially filled one fails with an "Incomplete value" pattern error.
readonlybooleanfalse- Prevents the user from editing the value while keeping the field focusable, and the value is still submitted with the form.
size'sm' | 'md' | 'lg''md'- Controls the input size. Options: 'sm', 'md', 'lg'.
formAssociatedbooleantruepropertiesobject{ // flag(), unlike `disabled`. The exclusion in props.js is specifically // about form-associated *platform* semantics: a `disabled` content // attribute that is merely present makes the element actually disabled // per the HTML spec, and formDisabledCallback assigns the property back, // so no converter can win. Neither of these is platform-mapped: // `required` is enforced by _computeValidity() below and `readonly` by // each component's own interaction handlers, so the stock converter buys // nothing here and costs the usual bug: `required="false"` read as true, // blocking submission of a form the author meant to leave optional. // Finding #48's shape, across all 26 form controls at once. required: flag(false), readonly: flag(false), }- Lit merges static properties up the prototype chain, so every consumer
gets these without declaring them.
requiredparticipates in constraint validation below;readonlyreflects for styling and is enforced by each component's interaction handlers (the mixin can't know which gestures mutate state). formvalidityvalidationMessage
Methods
checkValidity()boolean- Whether the control currently satisfies its constraints, per the native
constraint-validation API. Fires
invalidon the element when it does not, and reports nothing to the user. reportValidity()boolean- As checkValidity(), but also shows the browser's validation message against the control when it fails.
Events
arc-inputdetail:{ value: string, formatted: string }- Fired on each accepted edit.
valueis the raw characters;formattedis the presentation string. A rejected character fires nothing. arc-changedetail:{ value: string, formatted: string }- Fired on blur or Enter when the value changed, and immediately when the last mask position fills. A complete mask is a committed value (the fixed-length precedent set by OTP Input).
See also
- InputText field with a built-in label, placeholder and validation states. Set `multiline` for a textarea.
- Pin InputA row of one-character boxes for entering a PIN or a one-time code.
- Number InputA number field with minus and plus buttons that keeps the value between `min` and `max`.
- FormWraps ARC UI inputs in a form that validates them on submit and fires arc-submit with their values.