From 10b562e9decaefcfccdcd3341472f8208069385b Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Tue, 26 Nov 2024 11:06:39 +0530 Subject: [PATCH] Remove special character validations for names (patients and users) (#9177) --- public/locale/en.json | 1 + src/common/validation.tsx | 3 +-- src/components/Patient/PatientRegister.tsx | 12 ++++++++---- src/components/Users/UserAdd.tsx | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/public/locale/en.json b/public/locale/en.json index 5faa645b133..8a4a36a1a5c 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -869,6 +869,7 @@ "middleware_hostname": "Middleware Hostname", "middleware_hostname_example": "e.g. example.ohc.network", "middleware_hostname_sourced_from": "Middleware hostname sourced from {{ source }}", + "min_char_length_error": "Must be at least {{ min_length }} characters", "min_password_len_8": "Minimum password length 8", "min_time_bw_doses": "Min. time b/w doses", "minimize": "Minimize", diff --git a/src/common/validation.tsx b/src/common/validation.tsx index c7c084354a8..99b4342fbf6 100644 --- a/src/common/validation.tsx +++ b/src/common/validation.tsx @@ -38,8 +38,7 @@ export const getRandomNumbers = (min: number, max: number) => { }; export const validateName = (name: string) => { - const pattern = /^([a-zA-Z]*( [a-zA-Z])?)+$/; - return pattern.test(name); + return name.length >= 3; }; export const validateUsername = (username: string) => { diff --git a/src/components/Patient/PatientRegister.tsx b/src/components/Patient/PatientRegister.tsx index 2a15416e337..35d93214385 100644 --- a/src/components/Patient/PatientRegister.tsx +++ b/src/components/Patient/PatientRegister.tsx @@ -421,12 +421,16 @@ export const PatientRegister = (props: PatientRegisterProps) => { Object.keys(form).forEach((field) => { let phoneNumber, emergency_phone_number; switch (field) { - case "address": - case "name": - if (!validateName(form[field])) { - errors[field] = "Please enter valid name"; + case "name": { + const requiredError = RequiredFieldValidator()(form[field]); + if (requiredError) { + errors[field] = requiredError; + } else if (!validateName(form[field])) { + errors[field] = t("min_char_length_error", { min_length: 3 }); } return; + } + case "address": case "gender": errors[field] = RequiredFieldValidator()(form[field]); return; diff --git a/src/components/Users/UserAdd.tsx b/src/components/Users/UserAdd.tsx index 4c6c5edde2a..bfd38d2cae2 100644 --- a/src/components/Users/UserAdd.tsx +++ b/src/components/Users/UserAdd.tsx @@ -415,7 +415,7 @@ export const UserAdd = (props: UserProps) => { .join(" ")} is required`; invalidForm = true; } else if (!validateName(state.form[field])) { - errors[field] = "Please enter a valid name"; + errors[field] = t("min_char_length_error", { min_length: 3 }); invalidForm = true; } return;