validation

This commit is contained in:
Alex Holliday committed 2026-02-07 20:54:17 +00:00
1 parent af4c9d8f91
commit b6004241e7
8 files changed
+113 -10

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import { z } from "zod";
import { specialCharPattern } from "@/Validation/patterns";
export const passwordSchema = z
.object({
currentPassword: z.string().min(1, "Current password is required"),
newPassword: z
.string()
.min(1, "New password is required")
.min(8, "Password must be at least 8 characters")
.refine((val) => /[A-Z]/.test(val), "Password must contain an uppercase letter")
.refine((val) => /[a-z]/.test(val), "Password must contain a lowercase letter")
.refine((val) => /\d/.test(val), "Password must contain a number")
.refine(
(val) => specialCharPattern.test(val),
"Password must contain a special character"
),
confirm: z.string().min(1, "Please confirm your new password"),
})
.refine((data) => data.newPassword === data.confirm, {
message: "Passwords do not match",
path: ["confirm"],
});
export type PasswordFormData = z.infer<typeof passwordSchema>;
+4
View File
@@ -0,0 +1,4 @@
export const specialCharPattern = /[!?@#$%^&*()\-_=+[\]{};:'",.<>~`|\\/]/;
// Unicode-aware name pattern (allows letters, marks, apostrophes, parentheses, hyphens, periods, spaces)
export const namePattern = /^[\p{L}\p{M}''()\-\. ]+$/u;
+3 -4
View File
@@ -1,18 +1,17 @@
import { z } from "zod";
const NAME_PATTERN = /^[A-Za-z'-]+$/;
import { namePattern } from "@/Validation/patterns";
export const profileSchema = z.object({
firstName: z
.string()
.min(1, "First name is required")
.max(50, "First name must be 50 characters or less")
.regex(NAME_PATTERN, "First name can only contain letters, hyphens, and apostrophes"),
.regex(namePattern, "First name contains invalid characters"),
lastName: z
.string()
.min(1, "Last name is required")
.max(50, "Last name must be 50 characters or less")
.regex(NAME_PATTERN, "Last name can only contain letters, hyphens, and apostrophes"),
.regex(namePattern, "Last name contains invalid characters"),
profileImage: z.instanceof(File).optional().nullable(),
deleteProfileImage: z.boolean().optional(),
});
+1 -3
View File
@@ -1,7 +1,5 @@
import { z } from "zod";
const namePattern = /^[\p{L}\p{M}''()\-\. ]+$/u;
const specialCharPattern = /[!?@#$%^&*()\-_=+[\]{};:'",.<>~`|\\/]/;
import { specialCharPattern, namePattern } from "@/Validation/patterns";
export const registerSchema = z
.object({