From 3228d8d86978e972d1ca4333daccdfa160d75ea8 Mon Sep 17 00:00:00 2001 From: Vansh Gilhotra <140490653+Vansh5632@users.noreply.github.com> Date: Fri, 25 Jul 2025 03:33:49 +0530 Subject: [PATCH] refactor: A improvement fix related to optional phone validation (#22305) * fix:A bug related to optional phone validation * remove comment * fix: updated phone validation --------- Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> --- .../features/bookings/lib/getBookingResponsesSchema.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/features/bookings/lib/getBookingResponsesSchema.ts b/packages/features/bookings/lib/getBookingResponsesSchema.ts index d33ecf566c..d3e61a883d 100644 --- a/packages/features/bookings/lib/getBookingResponsesSchema.ts +++ b/packages/features/bookings/lib/getBookingResponsesSchema.ts @@ -276,8 +276,14 @@ function preprocess({ } if (bookingField.type === "phone") { - if (!bookingField.hidden && !(await phoneSchema.safeParseAsync(value)).success) { - ctx.addIssue({ code: z.ZodIssueCode.custom, message: m("invalid_number") }); + // Determine if the phone field needs validation + const needsValidation = isRequired || (value && value.trim() !== ""); + + // Validate phone number if the field is not hidden and requires validation + if (!bookingField.hidden && needsValidation) { + if (!(await phoneSchema.safeParseAsync(value)).success) { + ctx.addIssue({ code: z.ZodIssueCode.custom, message: m("invalid_number") }); + } } continue; }