Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve validation check for phone number in patient list page #8189 #8394

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a reusable validator for Phone Number form field. Avoid re-defining the validations for common ones.

https://github.com/coronasafe/care_fe/blob/develop/src/Components/Form/FieldValidators.tsx#L100


const setEmergencyPhoneNum = (emergency_phone_number: string) => {
Expand Down
Loading