KeyFilter

KeyFilter is a built-in feature of InputText to restrict user input based on a regular expression.


import { InputText } from 'primereact/inputtext';
         

KeyFilter provides various presets configured with the keyfilter property.


<InputText keyfilter="int" />
<InputText keyfilter="pint" />
<InputText keyfilter="num" />
<InputText keyfilter="pnum" />
<InputText keyfilter="money" />
<InputText keyfilter="hex" />
<InputText keyfilter="alpha" />
<InputText keyfilter="alphanum" />
<InputText keyfilter="email" />
         

In addition to the presets, a regular expression can be configured for customization of blocking a single key press.


<InputText keyfilter={/[^s]/} />
<InputText keyfilter={/^[^<>*!]+$/}  />
         

In addition to the presets, a regular expression can be used to validate the entire word using validateOnly.


<InputText id="numkeys" keyfilter={/^[+]?(d{1,12})?$/} validateOnly onInput={validateInput} />
         

Refer to InputText for accessibility as KeyFilter is a built-in add-on of the InputText.