Merged in feat/sw-2867-move-user-router-to-trpc-package (pull request #2428)
Move user router to trpc package * Move more schemas in hotel router * Fix deps * fix getNonContentstackUrls * Fix import error * Fix entry error handling * Fix generateMetadata metrics * Fix alertType enum * Fix duplicated types * lint:fix * Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package * Fix broken imports * Move booking router to trpc package * Move partners router to trpc package * Move autocomplete router to trpc package * Move booking router to trpc package * Remove translations from My Pages navigation trpc procedure * Move navigation router to trpc package * Move user router to trpc package * Merge branch 'master' into feat/sw-2862-move-booking-router-to-trpc-package * Merge branch 'feat/sw-2862-move-booking-router-to-trpc-package' into feat/sw-2865-move-navigation-router-to-trpc-package * Merge branch 'master' into feat/sw-2865-move-navigation-router-to-trpc-package * Merge branch 'master' into feat/sw-2865-move-navigation-router-to-trpc-package * Merge branch 'master' into feat/sw-2865-move-navigation-router-to-trpc-package * Merge branch 'feat/sw-2865-move-navigation-router-to-trpc-package' into feat/sw-2867-move-user-router-to-trpc-package * Merge branch 'master' into feat/sw-2867-move-user-router-to-trpc-package Approved-by: Linus Flood
This commit is contained in:
46
packages/common/utils/zod/passwordValidator.ts
Normal file
46
packages/common/utils/zod/passwordValidator.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const passwordValidators = {
|
||||
length: {
|
||||
matcher: (password: string) =>
|
||||
password.length >= 10 && password.length <= 40,
|
||||
message: "10 to 40 characters",
|
||||
},
|
||||
hasUppercase: {
|
||||
matcher: (password: string) => /[A-Z]/.test(password),
|
||||
message: "1 uppercase letter",
|
||||
},
|
||||
hasLowercase: {
|
||||
matcher: (password: string) => /[a-z]/.test(password),
|
||||
message: "1 lowercase letter",
|
||||
},
|
||||
hasNumber: {
|
||||
matcher: (password: string) => /[0-9]/.test(password),
|
||||
message: "1 number",
|
||||
},
|
||||
hasSpecialChar: {
|
||||
matcher: (password: string) =>
|
||||
/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/.test(password),
|
||||
message: "1 special character",
|
||||
},
|
||||
}
|
||||
|
||||
export const passwordValidator = (msg = "Required field") =>
|
||||
z
|
||||
.string()
|
||||
.min(1, msg)
|
||||
.refine(passwordValidators.length.matcher, {
|
||||
message: passwordValidators.length.message,
|
||||
})
|
||||
.refine(passwordValidators.hasUppercase.matcher, {
|
||||
message: passwordValidators.hasUppercase.message,
|
||||
})
|
||||
.refine(passwordValidators.hasLowercase.matcher, {
|
||||
message: passwordValidators.hasLowercase.message,
|
||||
})
|
||||
.refine(passwordValidators.hasNumber.matcher, {
|
||||
message: passwordValidators.hasNumber.message,
|
||||
})
|
||||
.refine(passwordValidators.hasSpecialChar.matcher, {
|
||||
message: passwordValidators.hasSpecialChar.message,
|
||||
})
|
||||
26
packages/common/utils/zod/phoneValidator.ts
Normal file
26
packages/common/utils/zod/phoneValidator.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const phoneErrors = {
|
||||
PHONE_NUMBER_TOO_SHORT: "PHONE_NUMBER_TOO_SHORT",
|
||||
PHONE_REQUESTED: "PHONE_REQUESTED",
|
||||
} as const
|
||||
|
||||
export function phoneValidator(
|
||||
msg = "Required field",
|
||||
invalidMsg = "Invalid type"
|
||||
) {
|
||||
return z
|
||||
.string({ invalid_type_error: invalidMsg, required_error: msg })
|
||||
.min(5, phoneErrors.PHONE_NUMBER_TOO_SHORT)
|
||||
.superRefine((value, ctx) => {
|
||||
if (value) {
|
||||
const containsAlphabeticChars = /[a-z]/gi.test(value)
|
||||
if (containsAlphabeticChars) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: phoneErrors.PHONE_REQUESTED,
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user