validation
This commit is contained in:
1 parent
af4c9d8f91
commit
b6004241e7
8 files changed
+113
-10
No files matched your search
@@ -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>;
|
||||
Reference in new issue
Block a user