lara-light-indigo

InputMask

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

Import via Module

import { InputMask } from 'primereact/inputmask';
 
Import via CDN

<script src="https://unpkg.com/primereact/core/core.min.js"></script>
<script src="https://unpkg.com/primereact/inputmask/inputmask.min.js"></script>
 
Getting Started

InputMask is used as a controlled component with value and onChange properties.


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

Mask format can be a combination of the the following built-in definitions.

  • a - Alpha character (A-Z,a-z)
  • 9 - Numeric character (0-9)
  • * - Alpha numberic character (A-Z,a-z,0-9)

<InputMask mask="a*-999-a999" value={value} onChange={(e) => setValue(e.value)}></InputMask>
 
SlotChar

Underscore is the default placeholder for a mask and this can be customized using slotChart option.


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

If the input does not complete the mask definition, it is cleared by default. Use autoClear property to control this behavior. In addition, certain part of a mask can be made optional by using ? symbol where anything after the question mark becomes optional.


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

InputMask passes any valid attribute to the underlying React HTMLInputElement element. Extended properties are as follows;

NameTypeDefaultDescription
idstringnullUnique identifier of the element.
valuestringnullValue of the component.
typestringtextHTML5 input type
maskstringnullMask pattern.
slotCharstring-Placeholder character in mask, default is underscore.
autoClearbooleantrueClears the incomplete value on blur.
unmaskbooleanfalseDefines if model sets the raw unmasked value to bound value or the formatted mask value.
stylestringnullInline style of the element.
classNamestringnullStyle class of the element.
placeholderstringnullAdvisory information to display on input.
sizenumbernullSize of the input field.
maxlengthnumbernullMaximum number of character allows in the input field.
tabIndexnumbernullSpecifies tab order of the element.
disabledbooleanfalseWhen present, it specifies that the element value cannot be altered.
readOnlybooleanfalseWhen present, it specifies that an input field is read-only.
namestringnullName of the input field.
requiredbooleanfalseWhen present, it specifies that the element must be filled out before submitting the form.
tooltipanynullContent of the tooltip.
tooltipOptionsobjectnullConfiguration of the tooltip, refer to the tooltip documentation for more information.
Events
NameParametersDescription
onFocusevent: Browser eventCallback to invoke when input receives focus.
onBlurevent: Browser eventCallback to invoke when input loses focus.
onCompleteevent: Browser event
value: New value of the component
Callback to invoke on when user completes the mask pattern.
onChangeoriginalEvent: Browser event
value: New value of the component
Callback to invoke on value change.
Styling

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
p-inputtextInput element
p-inputmaskInput element
Accessibility

This section is under development. After the necessary tests and improvements are made, it will be shared with the users as soon as possible.

Dependencies

None.

Component Scale

Input Style

Ripple Effect

Free Themes

Built-in component themes created by the PrimeReact Theme Designer.

Bootstrap
Blue
Purple
Blue
Purple
Material Design
Indigo
Deep Purple
Indigo
Deep Purple
Material Design Compact
Indigo
Deep Purple
Indigo
Deep Purple
Tailwind
Tailwind Light
Fluent UI
Blue
PrimeOne Design - 2022 NEW
Lara Indigo
Lara Blue
Lara Purple
Lara Teal
Lara Indigo
Lara Blue
Lara Purple
Lara Teal
PrimeOne Design - 2021
Saga Blue
Saga Green
Saga Orange
Saga Purple
Vela Blue
Vela Green
Vela Orange
Vela Purple
Arya Blue
Arya Green
Arya Orange
Arya Purple
Premium Themes

Premium themes are only available exclusively for PrimeReact Theme Designer subscribers and therefore not included in PrimeReact core.

Soho Light
Soho Dark
Viva Light
Viva Dark
Mira
Nano

Legacy Free Themes

Nova
Nova Alt
Nova Accent
Luna Blue
Luna Green
Luna Amber
Luna Pink
Rhea

Premium Create-React-App Templates

Beautifully crafted premium create-react-app application templates by the PrimeTek design team.

Sakai
Atlantis
Freya
Ultima
Diamond
Sapphire
Serenity
Babylon
Avalon
Apollo
Roma