Application · lesson 17 of 34 · Input And Data Entry

Input mask

Underlying principle: An input pattern carries a question, an expected answer, and a consequence. Visible labels, suitable controls, tolerant entry, and specific recovery keep that agreement clear.

Use an input mask to help users enter data that has a stable character structure, especially when grouping matches the physical document, card, container code, or serial key users are copying from.

Start with the decision

Does this fit your task?

The value has a stable character pattern and users benefit from live grouping.

Review the boundary: Compare the task with the alternatives in the decision section.

Review the decision →
Study the interaction

Follow the task before choosing the component

An input pattern carries a question, an expected answer, and a consequence. Visible labels, suitable controls, tolerant entry, and specific recovery keep that agreement clear.

01 / Recognize the need

What the person is doing

The field value has known character positions, group lengths, literal separators, or check digits.

02 / Design the response

What the interface must communicate

Use an input mask to help users enter data that has a stable character structure, especially when grouping matches the physical document, card, container code, or serial key users are copying from.

Empty untouched state with label and visible format example.

03 / Judge the outcome

What to look for

Is this value truly fixed-format, or are there legitimate exceptions?

Typing valid characters fills the next available mask slot and inserts literal separators automatically.

Decision first

Choose this pattern when the problem matches

Use when

  • The value has a stable character pattern and users benefit from live grouping.
  • Formatting mirrors a source users copy from, such as a card, container, serial label, or activation key.
  • The product can handle pasted values, partial values, exceptions, and canonical storage deliberately.

Avoid when

  • Valid values have many lengths, regions, scripts, or exception formats.
  • Users need to enter data in a different format than the mask supports.
  • The field is better handled by a picker, autocomplete, prefix/suffix, or ordinary text input.
  • The mask hides what will be submitted or stores separators inconsistently.

Problem it prevents

The field value has known character positions, group lengths, literal separators, or check digits.

Test the behavior

Try strong and weak versions of the interaction

Open the working example, try its controls, and compare the behavior against the decision guidance.

In the lab you can
  • switch between strong UI, weak UI, strong UX, and weak UX;
  • trigger required, empty, loading, error, and recovery states;
  • inspect keyboard and accessibility expectations beside the demo.
Launch Input mask in the lab
Pattern anatomy

What a strong implementation has to make clear

User need

The field value has known character positions, group lengths, literal separators, or check digits.

Pattern promise

Use an input mask to help users enter data that has a stable character structure, especially when grouping matches the physical document, card, container code, or serial key users are copying from.

Required state

Empty untouched state with label and visible format example.

Failure to inspect

The mask rejects real values with different lengths, regions, scripts, or exception formats.

Access contract

Connect hint, format example, canonical-value note, and error text to the input with descriptive relationships where supported.

Quality bar

The difference between expert and weak execution

Strong implementation

Specific, visible, recoverable

  • A container number field shows the example ABCD 123456 7, groups pasted characters into that shape, and displays the raw value ABCD1234567 before submit.
  • A user submits ABCD 123 and receives a precise error that the six-digit serial group and check digit are incomplete.
Weak implementation

Vague, hidden, hard to recover from

  • A phone field hard-codes a domestic mask and rejects valid international numbers.
  • The field shows underscores and separators as the only instruction, then jumps the cursor unpredictably when users paste or delete.
  • A user pastes a valid value with spaces and the mask discards characters because it only supports one-character-at-a-time typing.
  • The mask rejects real values with different lengths, regions, scripts, or exception formats.
UI guidance
  • Show a persistent label, visible example or hint, fixed grouping, literal separators, and field-adjacent error text so users understand which characters are typed and which are supplied by the mask.
  • Keep the entered value reviewable as both a formatted display value and, when relevant, a canonical stored value so users can see what will be submitted.
UX guidance
  • Use an input mask to help users enter data that has a stable character structure, especially when grouping matches the physical document, card, container code, or serial key users are copying from.
  • Preserve normal editing behavior: users must be able to paste, delete, select, correct the middle of the value, use undo, and submit without learning the mask implementation.
Implementation contract

What the implementation must handle

States

  • Empty untouched state with label and visible format example.
  • Partially entered state with incomplete groups and stable cursor behavior.
  • Pasted unformatted value normalized into the mask.
  • Invalid character attempted state with a non-blocking explanation or ignored-character status.

Interaction

  • Typing valid characters fills the next available mask slot and inserts literal separators automatically.
  • Pasting formatted or unformatted content normalizes into the same display value.
  • Deleting, selecting, replacing, undoing, and correcting middle groups remain predictable.
  • Submitting an incomplete mask keeps the partial value visible and names the missing group or character count.

Accessibility

  • Connect hint, format example, canonical-value note, and error text to the input with descriptive relationships where supported.
  • Ensure screen reader users can understand which characters they typed and which separators are supplied by the mask.
  • Avoid placeholder symbols that create noisy or misleading announcements.
  • Maintain visible focus, text selection, high-contrast affordances, and zoom-friendly grouping.

Review

  • Is this value truly fixed-format, or are there legitimate exceptions?
  • Can users paste the value from the source document and get the same result as typing?
  • Are separators stored, displayed only, copied, or stripped before submit?
  • Does the hint remain visible after the placeholder disappears?
Evidence trail

Source-backed claims behind this guidance

Maersk Design System: Input masks

Maersk Design System - checked

Maersk supports using masks for stable expected formats while preserving copy/paste and correction, and distinguishes masks from prefix/suffix or ordinary inputs.

SAP Fiori: Mask input

SAP - checked

SAP Fiori supports mandatory labels, mask patterns, immutable characters, aria-described guidance, paste behavior, deletion behavior, and mask avoidance when valid data would be blocked.

Material Design: Text fields

Google Material Design - checked

Material Design supports grouped formatted input, helper text, error text, and prefix/suffix alternatives for text fields.

Full agent/debug reference

Problem Context

  • The field value has known character positions, group lengths, literal separators, or check digits.
  • Users often copy the value from a document, card, label, shipment record, serial plate, or system-generated code.
  • The grouped display reduces transcription errors and matches the user's source material.
  • The product can define whether separators are stored, displayed only, copied, or stripped before backend validation.
  • Valid exceptions, localization, alternate lengths, or picker-based entry have been checked before choosing a mask.

Selection Rules

  • Choose input mask when the value has a stable, narrow structure with predictable character classes and grouping.
  • Use text input when users may need to enter values outside one fixed structure, such as company names, freeform identifiers, or international contact details.
  • Use inline validation when normal typing should remain unconstrained and the system can explain a format error after blur or submit.
  • Use autocomplete when the typed value should resolve to an existing record instead of merely being shaped into a format.
  • Use prefix/suffix when a constant symbol, unit, currency, or domain is separate from the user's typed value.
  • Use a date picker, time picker, or domain-specific picker when the picker owns entry and masks would conflict with it.
  • Do not mask emails, broad phone-number formats, addresses, names, or values with common legitimate exceptions.
  • Keep hint text visible for complex formats; do not rely on placeholder mask characters alone.
  • Support paste from both formatted and unformatted values.
  • State or reveal whether literals are included in copied and submitted values.

Required States

  • Empty untouched state with label and visible format example.
  • Focused state that reveals grouping or mask affordance without replacing the label.
  • Partially entered state with incomplete groups and stable cursor behavior.
  • Pasted unformatted value normalized into the mask.
  • Pasted formatted value accepted without duplicating separators.
  • Invalid character attempted state with a non-blocking explanation or ignored-character status.
  • Incomplete required value error after submit.
  • Complete formatted display state with canonical stored value visible or inspectable.
  • Deletion or correction state where placeholders do not shift remaining characters unpredictably.
  • Exception or unsupported-format state with a fallback path.

Interaction Contract

  • Typing valid characters fills the next available mask slot and inserts literal separators automatically.
  • Typing invalid characters either ignores them with a clear status or leaves the value unchanged without corrupting existing characters.
  • Pasting formatted or unformatted content normalizes into the same display value.
  • Deleting, selecting, replacing, undoing, and correcting middle groups remain predictable.
  • Submitting an incomplete mask keeps the partial value visible and names the missing group or character count.
  • The canonical value sent to the backend is derived deterministically and can be validated server-side.
  • The mask does not remove browser, keyboard, or assistive technology access to label, hint, and error text.

Implementation Checklist

  • Define the canonical value, formatted display value, accepted character classes, group lengths, literals, optional groups, and storage behavior before building the UI.
  • Choose native input attributes such as inputmode, autocomplete, autocapitalize, maxlength, spellcheck, and aria-describedby to match the data type.
  • Normalize paste from formatted and unformatted sources and test paste with spaces, dashes, parentheses, lowercase letters, and clipboard content longer than the mask.
  • Preserve user control over deletion, selection, overwrite, cursor movement, undo, redo, and browser autofill.
  • Validate the canonical value on client and server and show incomplete or invalid-group errors next to the field.
  • Provide visible helper text for the expected format and do not make placeholder mask characters the only instruction.
  • Test localization, right-to-left layouts, screen readers, mobile keyboards, zoom, saved drafts, browser Back, copy behavior, and exception values.

Common Generated-UI Mistakes

  • Using a mask because a format exists even though many valid values do not fit it.
  • Rejecting pasted values that include spaces, dashes, parentheses, or lowercase characters.
  • Letting separators appear in the field but silently storing a different value without user or developer clarity.
  • Using underscores or placeholder symbols as the only format guidance.
  • Breaking deletion or middle-character correction so users must clear the entire field.
  • Combining a mask with a picker or prefix/suffix that should own the format instead.
  • Masking data that needs localization or exception handling without a fallback.

Critique Questions

  • Is this value truly fixed-format, or are there legitimate exceptions?
  • Can users paste the value from the source document and get the same result as typing?
  • Can users correct one middle character without retyping the field?
  • Are separators stored, displayed only, copied, or stripped before submit?
  • Does the hint remain visible after the placeholder disappears?
  • Would text input plus inline validation, autocomplete, prefix/suffix, or a picker be less fragile?
Accessibility
  • Keep a real visible label and do not use the mask pattern or placeholder as a substitute for the field name.
  • Connect hint, format example, canonical-value note, and error text to the input with descriptive relationships where supported.
  • Do not announce every inserted separator as a disruptive status update; reserve live regions for meaningful validation or paste-normalization changes.
  • Ensure screen reader users can understand which characters they typed and which separators are supplied by the mask.
  • Avoid placeholder symbols that create noisy or misleading announcements.
  • Maintain visible focus, text selection, high-contrast affordances, and zoom-friendly grouping.
Keyboard Behavior
  • Tab moves to the field in normal order and does not focus literal separators separately.
  • Typing fills the next editable slot while separators are inserted or skipped predictably.
  • Backspace and Delete remove editable characters without trapping focus or corrupting remaining groups.
  • Arrow keys, Home, End, selection shortcuts, paste, undo, and redo behave as close to native text editing as possible.
  • Submit with an incomplete mask moves focus to the error summary or masked field without clearing the partial value.
  • Mobile keyboards expose the needed letters, numbers, and symbols for the mask.
Variants
  • Grouped card number mask
  • Container number mask
  • Serial key mask
  • Postal code mask
  • Phone mask with fallback
  • Date mask fallback
  • Mask with literal separators
  • Mask with optional groups
  • Mask with canonical value preview
  • Paste-normalizing mask

Verification

Source trail checked:

Saved items