Introducing PrimeReact v11-alpha 🎉Discover Now
styledForm

InputMask

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

Usage#

import { useMask } from '@primereact/hooks/use-mask';
const mask = useMask();

Examples#

Basic#

basic-demo

Format Patterns#

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.

mask-demo

Optional#

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

optional-demo

Slot Character#

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

slot-char-demo

Unmask#

By default the bound value contains the formatted mask. Enable unmask option to receive the raw value without the mask characters.

Unmasked value:
unmask-demo

AutoClear#

When autoClear is set to false, the incomplete value is preserved on blur instead of being cleared.

auto-clear-demo