Introducing PrimeReact v11-alpha 🎉Discover Now

useMask

useMask 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.

format-patterns-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