📄 primereact/inputmask

File: inputmask.md | Updated: 11/15/2025

Source: https://primereact.org/inputmask/

Introducing PrimeReact v11 Alpha 🥁Learn More

InputMask

InputMask component is used to enter input in a certain format such as numeric, date, currency, email and phone.

Import#


import { InputMask } from 'primereact/inputmask';
         

Copy

Basic#


InputMask is used as a controlled input with value and onChange properties along with the mask property to define the mask.

<InputMask value={value} onChange={(e) => setValue(e.target.value)} mask="99-999999" placeholder="99-999999" />
         

Copy

Mask#


Mask format can be a combination of the following definitions; a for alphabetic characters, 9 for numeric characters and * for alphanumberic characters. In addition, formatting characters like ( , ) , - are also accepted.

SSN

Phone

Serial

<label htmlFor="ssn" className="font-bold block mb-2">SSN</label>
<InputMask id="ssn" mask="999-99-9999" placeholder="999-99-9999"></InputMask>

<label htmlFor="phone" className="font-bold block mb-2">Phone</label>
<InputMask id="phone" mask="(999) 999-9999" placeholder="(999) 999-9999"></InputMask>

<label htmlFor="serial" className="font-bold block mb-2">Serial</label>
<InputMask id="serial" mask="a*-999-a999" placeholder="a*-999-a999"></InputMask>
         

Copy

Optional#


When the input does not complete the mask definition, it is cleared by default. Use autoClear property to control this behavior. In addition, ? is used to mark anything after the question mark optional.

<InputMask value={value} onChange={(e) => setValue(e.target.value)} mask="(999) 999-9999? x99999" placeholder="(999) 999-9999? x99999"  />
         

Copy

Slot Char#


Default placeholder for a mask is underscore that can be customized using slotChar property.

<InputMask value={value} onChange={(e) => setValue(e.target.value)} mask="99/99/9999" placeholder="99/99/9999" slotChar="mm/dd/yyyy" />
         

Copy

Float Label#


A floating label appears on top of the input field when focused. Visit FloatLabel documentation for more information.

SSN

<FloatLabel>
    <InputMask id="ssn_input" value={value} onChange={(e) => setValue(e.target.value)} mask="999-99-9999" />
    <label htmlFor="ssn_input">SSN</label>
</FloatLabel>
         

Copy

Filled#


Specify the variant property as filled to display the component with a higher visual emphasis than the default outlined style.

<InputMask variant="filled" value={value} onChange={(e) => setValue(e.target.value)} mask="99-999999" placeholder="99-999999" />
         

Copy

Invalid#


Invalid state is displayed using the invalid prop to indicate a failed validation. You can use this style when integrating with form validation libraries.

<InputMask invalid mask="99-999999" placeholder="99-999999" />
         

Copy

Disabled#


When disabled is present, the element cannot be edited and focused.

<InputMask mask="99-999999" placeholder="99-999999" disabled />
         

Copy

Accessibility#


Screen Reader

InputMask component renders a native input element that implicitly includes any passed prop. Value to describe the component can either be provided via label tag combined with id prop or using aria-labelledby, aria-label props.

<label htmlFor="date">Date</label>
<InputMask id="date" />

<span id="phone">Phone</span>
<InputMask aria-labelledby="phone" />

<InputMask aria-label="Age" />
     

Copy

Keyboard Support

| Key | Function | | --- | --- | | tab | Moves focus to the input. |

  • Import

  • Basic

  • Mask

  • Optional

  • Slot Char

  • Float Label

  • Filled

  • Invalid

  • Disabled

  • Accessibility

PrimeReact 10.9.7 by PrimeTek