Skip to main content

Masked input

Note: There are deprecated versions of this component. Switch to a version of the docs older than 10.3.x to view their docs.

Usage

Overview

An input mask guides users in entering data by constraining and shaping the information into a specific format as it is entered.

You can apply a mask to the text input field and the phone input field.

When to use

In fields with a specific expected format such as Social Security Number or ZIP code.

When not to use

  • For input that requires a free-form field.
  • When the input pattern is too complex for a mask. For example, an email address has many possible scenarios for input.

Formatting

Anatomy

Image depicting the anatomy of a phone input field with an input mask Example of the phone input field with an input mask.

  1. Label: Describes the purpose of an input field.
  2. Input mask: A string expression that constrains input to support valid input values. The input mask appears on focus.
  3. Phone input field: Enhanced field that enables users to enter their phone number. It only accepts numeric inputs and is automatically formatted.

Content

For content standards, refer to text input and phone input writing guidelines.

Behaviors

The input mask appears as soon as there is a focus on the field. Before focus, the input is empty or displays placeholder text.

Image illustrating the text input field in the enabled state and focus state Example of an enabled text input field (on the left), and a focused text input field (on the right).

Accessibility

The contrast ratio of textual elements against their background is above 4.5:1 as per WCAG 2.1 AA requirements. Non-textual content that needs to convey meaning (such as icons and keyboard focus visibility) has a contrast ratio of at least 3:1 with its adjacent colors. All content is visible and functional up to and including 400% without requiring scrolling in two dimensions.

This component has been validated to meet the WCAG 2.1 AA accessibility guidelines. However, changes made by the content author can affect accessibility conformance.

When using this component within your application, ensure that labels and instructions are meaningful and concise. Provide supplemental instructions if necessary.