File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,4 +4,15 @@ import { z } from "zod";
44export const emailRegex =
55 / ^ (? ! \. ) (? ! .* \. \. ) ( [ A - Z 0 - 9 _ + -\. ' ] * ) [ A - Z 0 - 9 _ + ' - ] @ ( [ A - Z 0 - 9 ] [ A - Z 0 - 9 \- ] * \. ) + [ A - Z ] { 2 , } $ / i;
66
7- export const emailSchema = z . string ( ) . regex ( emailRegex ) ;
7+ /**
8+ * RFC 5321 Section 4.5.3.1.3 specifies:
9+ * - Maximum email address length: 254 characters
10+ * - Local part (before @): max 64 characters
11+ * - Domain part (after @): max 253 characters
12+ */
13+ const MAX_EMAIL_LENGTH = 254 ;
14+
15+ export const emailSchema = z
16+ . string ( )
17+ . max ( MAX_EMAIL_LENGTH , { message : "Email address is too long" } )
18+ . regex ( emailRegex ) ;
Original file line number Diff line number Diff line change @@ -709,7 +709,7 @@ export const emailSchema = emailRegexSchema;
709709// I introduced this refinement(to be used with z.email()) as a short term solution until we upgrade to a zod
710710// version that will include updates in the above PR.
711711export const emailSchemaRefinement = ( value : string ) => {
712- return emailRegex . test ( value ) ;
712+ return emailSchema . safeParse ( value ) . success ;
713713} ;
714714
715715export const signupSchema = z . object ( {
You can’t perform that action at this time.
0 commit comments