feat: validate optional membership number for non-logged in users

This commit is contained in:
Simon Emanuelsson
2024-11-07 13:16:23 +01:00
parent 4e3bb9a334
commit 66f4a310d3
4 changed files with 46 additions and 16 deletions

View File

@@ -16,6 +16,21 @@ export const notJoinDetailsSchema = baseDetailsSchema.merge(
zipCode: z.string().optional(),
dateOfBirth: z.string().optional(),
termsAccepted: z.boolean().default(false),
membershipNo: z
.string()
.optional()
.refine((val) => {
if (val) {
return !val.match(/[^0-9]/g)
}
return true
}, "Only digits are allowed")
.refine((num) => {
if (num) {
return num.length === 14
}
return true
}, "Membership number needs to be 14 digits"),
})
)
@@ -33,6 +48,7 @@ export const joinDetailsSchema = baseDetailsSchema.merge(
return { message: ctx.defaultError }
},
}),
membershipNo: z.string().optional(),
})
)