Restrict the length of emails as per RFC (#24269)

This commit is contained in:
Hariom Balhara
2025-10-06 10:22:58 +00:00
committed by GitHub
parent 7799b191ec
commit bbe46eaa7d
2 changed files with 13 additions and 2 deletions
+12 -1
View File
@@ -4,4 +4,15 @@ import { z } from "zod";
export const emailRegex =
/^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.']*)[A-Z0-9_+'-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
export const emailSchema = z.string().regex(emailRegex);
/**
* RFC 5321 Section 4.5.3.1.3 specifies:
* - Maximum email address length: 254 characters
* - Local part (before @): max 64 characters
* - Domain part (after @): max 253 characters
*/
const MAX_EMAIL_LENGTH = 254;
export const emailSchema = z
.string()
.max(MAX_EMAIL_LENGTH, { message: "Email address is too long" })
.regex(emailRegex);
+1 -1
View File
@@ -709,7 +709,7 @@ export const emailSchema = emailRegexSchema;
// I introduced this refinement(to be used with z.email()) as a short term solution until we upgrade to a zod
// version that will include updates in the above PR.
export const emailSchemaRefinement = (value: string) => {
return emailRegex.test(value);
return emailSchema.safeParse(value).success;
};
export const signupSchema = z.object({