Introducing PrimeReact v11-alpha 🎉Discover Now

useKeyFilter

useKeyFilter used to block individual keystrokes based on a pattern.

Usage#

import { useKeyFilter } from '@primereact/hooks/use-key-filter';
const keyfilter = useKeyFilter();

Examples#

Pattern#

useKeyFilter provides various presets configured with the pattern option.

pattern-demo

Regex#

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

regex-demo

Regex Word#

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

regex-word-demo