KeyFilter

KeyFilter is a directive to restrict individual key strokes. In order to restrict the whole input, use InputNumber or InputMask instead.


import { KeyFilter } from 'primeng/keyfilter';

KeyFilter provides various presets configured with the pKeyFilter property.


<input pInputText pKeyFilter="int" />
<input pInputText pKeyFilter="num" />
<input pInputText pKeyFilter="money" />
<input pInputText pKeyFilter="hex" />
<input pInputText pKeyFilter="alpha" />
<input pInputText pKeyFilter="alphanum" />

In addition to the presets, a regular expression can be configured for customization.


<input pInputText [pKeyFilter]="blockSpace" />
<input pInputText [pKeyFilter]="blockChars" />

KeyFilter can also be used with reactive forms. In this case, the formControlName property is used to bind the component to a form control.


<form [formGroup]="formGroup">
    <label for="integer" class="font-bold block mb-2"> Integer </label>
    <input pInputText id="integer" pKeyFilter="int" class="w-full" formControlName="value" />
</form>

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