From 2837e5086921b4aeef16ffd684cac26c1fb72c62 Mon Sep 17 00:00:00 2001 From: ArtemHolikov <102384883+ArtemHolikov@users.noreply.github.com> Date: Wed, 4 Dec 2024 23:35:45 +0200 Subject: [PATCH] invalid characters are unavailable for name fields (#2819) --- src/hooks/use-form.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/hooks/use-form.tsx b/src/hooks/use-form.tsx index fa4a6df71..3978540d4 100644 --- a/src/hooks/use-form.tsx +++ b/src/hooks/use-form.tsx @@ -70,10 +70,20 @@ export const useForm = ({ const handleInputChange = (key: keyof T) => (event: React.ChangeEvent) => { - const value = + const nameRegex = /[^a-zA-Z\u0400-\u04FF]/g + + let value = event.target.type === 'checkbox' ? event.target.checked : event.target.value + + if ( + (key === 'firstName' || key === 'lastName') && + typeof value === 'string' + ) { + value = value.replace(nameRegex, '') + } + setData((prev) => { const newData = { ...prev,