Skip to content

Commit

Permalink
Improve validation check for phone number in patient list page ohcne…
Browse files Browse the repository at this point in the history
  • Loading branch information
Nithin9585 committed Aug 22, 2024
1 parent a65681e commit d4c4368
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Components/Patient/ManagePatients.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit d4c4368

Please sign in to comment.