diff --git a/apps/portal/src/features/get-started/components/GetStartedForm/steps/complete-account/useCompleteAccountForm.ts b/apps/portal/src/features/get-started/components/GetStartedForm/steps/complete-account/useCompleteAccountForm.ts index c55c0aaf..9ec548c8 100644 --- a/apps/portal/src/features/get-started/components/GetStartedForm/steps/complete-account/useCompleteAccountForm.ts +++ b/apps/portal/src/features/get-started/components/GetStartedForm/steps/complete-account/useCompleteAccountForm.ts @@ -2,6 +2,7 @@ import { useState, useCallback } from "react"; import { type JapanAddressFormData } from "@/features/address/components/JapanAddressForm"; import { prepareWhmcsAddressFields } from "@customer-portal/domain/address"; import { validatePasswordRules } from "@/features/auth/hooks/usePasswordValidation"; +import { phoneSchema } from "@customer-portal/domain/common"; import type { AccountFormErrors } from "./types"; interface FormState { @@ -90,7 +91,14 @@ export function useCompleteAccountForm({ const passwordError = validatePasswordRules(password); if (passwordError) newErrors.password = passwordError; if (password !== confirmPassword) newErrors.confirmPassword = "Passwords do not match"; - if (!phone.trim()) newErrors.phone = "Phone number is required"; + if (phone.trim()) { + const phoneResult = phoneSchema.safeParse(phone.trim()); + if (!phoneResult.success) { + newErrors.phone = "Please enter a valid phone number"; + } + } else { + newErrors.phone = "Phone number is required"; + } if (!dateOfBirth) newErrors.dateOfBirth = "Date of birth is required"; if (!gender) newErrors.gender = "Please select a gender"; if (!acceptTerms) newErrors.acceptTerms = "You must accept the terms of service"; diff --git a/apps/portal/src/features/services/components/eligibility-check/steps/CompleteAccountStep.tsx b/apps/portal/src/features/services/components/eligibility-check/steps/CompleteAccountStep.tsx index 1f248ebc..e43ca47c 100644 --- a/apps/portal/src/features/services/components/eligibility-check/steps/CompleteAccountStep.tsx +++ b/apps/portal/src/features/services/components/eligibility-check/steps/CompleteAccountStep.tsx @@ -15,6 +15,7 @@ import { validatePasswordRules, usePasswordValidation, } from "@/features/auth/hooks/usePasswordValidation"; +import { phoneSchema } from "@customer-portal/domain/common"; import { useEligibilityCheckStore } from "../../../stores/eligibility-check.store"; import { AccountInfoDisplay, PersonalInfoFields, PasswordSection } from "./complete-account"; @@ -59,7 +60,14 @@ export function CompleteAccountStep() { if (passwordError) errors.password = passwordError; if (accountData.password !== accountData.confirmPassword) errors.confirmPassword = "Passwords do not match"; - if (!accountData.phone.trim()) errors.phone = "Phone number is required"; + if (accountData.phone.trim()) { + const phoneResult = phoneSchema.safeParse(accountData.phone.trim()); + if (!phoneResult.success) { + errors.phone = "Please enter a valid phone number"; + } + } else { + errors.phone = "Phone number is required"; + } if (!accountData.dateOfBirth) errors.dateOfBirth = "Date of birth is required"; if (!accountData.gender) errors.gender = "Please select a gender"; if (!accountData.acceptTerms) errors.acceptTerms = "You must accept the terms of service";