From d4c43683304bd8802565259aab7d1de9847bb6ec Mon Sep 17 00:00:00 2001 From: Nithin Date: Thu, 22 Aug 2024 15:13:53 +0530 Subject: [PATCH] Improve validation check for phone number in patient list page #8189 --- src/Components/Patient/ManagePatients.tsx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index 1177053dee4..731e80ab7bb 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -112,19 +112,22 @@ export const PatientManager = () => { const setPhoneNum = (phone_number: string) => { setPhoneNumber(phone_number); - if (phone_number.length >= 13) { - setPhoneNumberError(""); - updateQuery({ phone_number }); - return; - } - if (phone_number === "+91" || phone_number === "") { + if (phone_number.length >= 13) { + if (isValidPhoneNumber(phone_number)) { + setPhoneNumberError(""); + updateQuery({ phone_number }); + } else { + setPhoneNumberError("Enter a valid number"); + } + } else { setPhoneNumberError(""); - qParams.phone_number && updateQuery({ phone_number: null }); - return; } + }; - setPhoneNumberError("Enter a valid number"); + const isValidPhoneNumber = (phoneNumber: string) => { + const phoneNumberRegex = /^\+91[0-9]{10}$/; + return phoneNumberRegex.test(phoneNumber); }; const setEmergencyPhoneNum = (emergency_phone_number: string) => {