add phone number validation to update account form

This commit is contained in:
2025-09-08 00:59:17 +03:00
parent 96eea95fb9
commit 7815a1c011
5 changed files with 42 additions and 38 deletions

View File

@@ -1,4 +1,5 @@
import { z } from 'zod';
import parsePhoneNumber from 'libphonenumber-js/min';
export const UpdateAccountSchema = z.object({
firstName: z
@@ -23,7 +24,20 @@ export const UpdateAccountSchema = z.object({
.string({
error: 'Phone number is required',
})
.nonempty(),
.nonempty()
.refine(
(phone) => {
try {
const phoneNumber = parsePhoneNumber(phone);
return !!phoneNumber && phoneNumber.isValid() && phoneNumber.country === 'EE';
} catch {
return false;
}
},
{
message: 'common:formFieldError.invalidPhoneNumber',
}
),
city: z.string().optional(),
weight: z
.number({