KeyFilter

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


import { KeyFilterModule } 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.