From b0c32fbc1e6782395068058e69a88e48c190c4e8 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 6 May 2024 00:27:56 +0200 Subject: [PATCH 1/5] Added e164 validation --- deno/lib/ZodError.ts | 1 + deno/lib/__tests__/string.test.ts | 37 +++++++++++++++++++++++++++++++ deno/lib/types.ts | 26 ++++++++++++++++++++++ src/ZodError.ts | 1 + src/__tests__/string.test.ts | 37 +++++++++++++++++++++++++++++++ src/types.ts | 20 +++++++++++++++++ 6 files changed, 122 insertions(+) diff --git a/deno/lib/ZodError.ts b/deno/lib/ZodError.ts index 732a666f1..e085a8cdf 100644 --- a/deno/lib/ZodError.ts +++ b/deno/lib/ZodError.ts @@ -113,6 +113,7 @@ export type StringValidation = | "duration" | "ip" | "base64" + | "e164" | { includes: string; position?: number } | { startsWith: string } | { endsWith: string }; diff --git a/deno/lib/__tests__/string.test.ts b/deno/lib/__tests__/string.test.ts index 2cd1a5a4c..035b9f22f 100644 --- a/deno/lib/__tests__/string.test.ts +++ b/deno/lib/__tests__/string.test.ts @@ -906,3 +906,40 @@ test("IP validation", () => { invalidIPs.every((ip) => ipSchema.safeParse(ip).success === false) ).toBe(true); }); + +test("E.164 validation", () => { + const e164Number = z.string().e164(); + expect(e164Number.safeParse("+1555555").success).toBe(true); + + const validE164Numbers = [ + "+1555555", // min-length (7 + 1) + "+15555555", + "+155555555", + "+1555555555", + "+15555555555", + "+155555555555", + "+1555555555555", + "+15555555555555", + "+155555555555555", + "+105555555555555", + "+100555555555555", // max-length (15 + 1) + ]; + + const invalidE164Numbers = [ + "", // empty + "+", // only plus sign + "-", // wrong sign + "555555555", // missing plus sign + "+1 555 555 555", // space after plus sign + "+1555 555 555", // space after plus sign + "+1555 555 555", // space between numbers + "+1555+555", // multiple plus signs + "+1555555555555555", // too long + "+115abc55", // non numeric characters in number part + ]; + + expect(validE164Numbers.every((number) => e164Number.safeParse(number).success)).toBe(true); + expect( + invalidE164Numbers.every((number) => e164Number.safeParse(number).success === false) + ).toBe(true); +}); diff --git a/deno/lib/types.ts b/deno/lib/types.ts index d85060f00..f82e1ac26 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -551,7 +551,11 @@ export type ZodStringCheck = | { kind: "duration"; message?: string } | { kind: "ip"; version?: IpVersion; message?: string } | { kind: "base64"; message?: string } +<<<<<<< HEAD | { kind: "json"; message?: string }; +======= + | { kind: "e164"; message?: string }; +>>>>>>> 84694186 (Added e164 validation) export interface ZodStringDef extends ZodTypeDef { checks: ZodStringCheck[]; @@ -618,9 +622,14 @@ const ipv6Regex = const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/; +<<<<<<< HEAD // based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address const hostnameRegex = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/; +======= +// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex from there allows spaces) +const e164Regex = /^\+(?:[0-9]){6,14}[0-9]$/; +>>>>>>> 84694186 (Added e164 validation) // simple // const dateRegexSource = `\\d{4}-\\d{2}-\\d{2}`; @@ -1035,6 +1044,16 @@ export class ZodString extends ZodType { message: check.message, }); } + } else if (check.kind === "e164") { + if (!e164Regex.test(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + validation: "e164", + code: ZodIssueCode.invalid_string, + message: check.message, + }); + status.dirty(); + } } else { util.assertNever(check); } @@ -1122,6 +1141,10 @@ export class ZodString extends ZodType { return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) }); } + e164(message?: errorUtil.ErrMessage) { + return this._addCheck({ kind: "e164", ...errorUtil.errToObj(message) }); + } + datetime( options?: | string @@ -1353,6 +1376,9 @@ export class ZodString extends ZodType { get isBase64() { return !!this._def.checks.find((ch) => ch.kind === "base64"); } + get isE164() { + return !!this._def.checks.find((ch) => ch.kind === "e164"); + } get minLength() { let min: number | null = null; diff --git a/src/ZodError.ts b/src/ZodError.ts index 20390857a..35657fe14 100644 --- a/src/ZodError.ts +++ b/src/ZodError.ts @@ -113,6 +113,7 @@ export type StringValidation = | "duration" | "ip" | "base64" + | "e164" | { includes: string; position?: number } | { startsWith: string } | { endsWith: string }; diff --git a/src/__tests__/string.test.ts b/src/__tests__/string.test.ts index 0e7152db6..7cecae9ca 100644 --- a/src/__tests__/string.test.ts +++ b/src/__tests__/string.test.ts @@ -905,3 +905,40 @@ test("IP validation", () => { invalidIPs.every((ip) => ipSchema.safeParse(ip).success === false) ).toBe(true); }); + +test("E.164 validation", () => { + const e164Number = z.string().e164(); + expect(e164Number.safeParse("+1555555").success).toBe(true); + + const validE164Numbers = [ + "+1555555", // min-length (7 + 1) + "+15555555", + "+155555555", + "+1555555555", + "+15555555555", + "+155555555555", + "+1555555555555", + "+15555555555555", + "+155555555555555", + "+105555555555555", + "+100555555555555", // max-length (15 + 1) + ]; + + const invalidE164Numbers = [ + "", // empty + "+", // only plus sign + "-", // wrong sign + "555555555", // missing plus sign + "+1 555 555 555", // space after plus sign + "+1555 555 555", // space after plus sign + "+1555 555 555", // space between numbers + "+1555+555", // multiple plus signs + "+1555555555555555", // too long + "+115abc55", // non numeric characters in number part + ]; + + expect(validE164Numbers.every((number) => e164Number.safeParse(number).success)).toBe(true); + expect( + invalidE164Numbers.every((number) => e164Number.safeParse(number).success === false) + ).toBe(true); +}); diff --git a/src/types.ts b/src/types.ts index 1c591253d..8d2411e66 100644 --- a/src/types.ts +++ b/src/types.ts @@ -552,6 +552,7 @@ export type ZodStringCheck = | { kind: "ip"; version?: IpVersion; message?: string } | { kind: "base64"; message?: string } | { kind: "json"; message?: string }; + | { kind: "e164"; message?: string }; export interface ZodStringDef extends ZodTypeDef { checks: ZodStringCheck[]; @@ -621,6 +622,8 @@ const base64Regex = // based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address const hostnameRegex = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/; +// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex from there allows spaces) +const e164Regex = /^\+(?:[0-9]){6,14}[0-9]$/; // simple // const dateRegexSource = `\\d{4}-\\d{2}-\\d{2}`; @@ -1035,6 +1038,16 @@ export class ZodString extends ZodType { message: check.message, }); } + } else if (check.kind === "e164") { + if (!e164Regex.test(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + validation: "e164", + code: ZodIssueCode.invalid_string, + message: check.message, + }); + status.dirty(); + } } else { util.assertNever(check); } @@ -1122,6 +1135,10 @@ export class ZodString extends ZodType { return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) }); } + e164(message?: errorUtil.ErrMessage) { + return this._addCheck({ kind: "e164", ...errorUtil.errToObj(message) }); + } + datetime( options?: | string @@ -1353,6 +1370,9 @@ export class ZodString extends ZodType { get isBase64() { return !!this._def.checks.find((ch) => ch.kind === "base64"); } + get isE164() { + return !!this._def.checks.find((ch) => ch.kind === "e164"); + } get minLength() { let min: number | null = null; From 4cd4fe0bb20ac7a9d7a79252b74af31a310dcc8a Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 9 May 2024 00:25:26 +0100 Subject: [PATCH 2/5] cleanup and missing files --- README.md | 1 + deno/lib/README.md | 1 + deno/lib/__tests__/string.test.ts | 7 ++++--- deno/lib/types.ts | 4 ++++ src/__tests__/string.test.ts | 7 ++++--- src/types.ts | 6 +++--- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d31162d9f..5c61272b9 100644 --- a/README.md +++ b/README.md @@ -652,6 +652,7 @@ z.string().date(); // ISO date format (YYYY-MM-DD) z.string().time(); // ISO time format (HH:mm:ss[.SSSSSS]) z.string().duration(); // ISO 8601 duration z.string().base64(); +z.string().e164(); // E.164 number format ``` > Check out [validator.js](https://github.com/validatorjs/validator.js) for a bunch of other useful string validation functions that can be used in conjunction with [Refinements](#refine). diff --git a/deno/lib/README.md b/deno/lib/README.md index d31162d9f..5c61272b9 100644 --- a/deno/lib/README.md +++ b/deno/lib/README.md @@ -652,6 +652,7 @@ z.string().date(); // ISO date format (YYYY-MM-DD) z.string().time(); // ISO time format (HH:mm:ss[.SSSSSS]) z.string().duration(); // ISO 8601 duration z.string().base64(); +z.string().e164(); // E.164 number format ``` > Check out [validator.js](https://github.com/validatorjs/validator.js) for a bunch of other useful string validation functions that can be used in conjunction with [Refinements](#refine). diff --git a/deno/lib/__tests__/string.test.ts b/deno/lib/__tests__/string.test.ts index 035b9f22f..c7a835189 100644 --- a/deno/lib/__tests__/string.test.ts +++ b/deno/lib/__tests__/string.test.ts @@ -912,7 +912,7 @@ test("E.164 validation", () => { expect(e164Number.safeParse("+1555555").success).toBe(true); const validE164Numbers = [ - "+1555555", // min-length (7 + 1) + "+1555555", // min-length (7 digits + '+') "+15555555", "+155555555", "+1555555555", @@ -922,20 +922,21 @@ test("E.164 validation", () => { "+15555555555555", "+155555555555555", "+105555555555555", - "+100555555555555", // max-length (15 + 1) + "+100555555555555", // max-length (15 digits + '+') ]; const invalidE164Numbers = [ "", // empty "+", // only plus sign "-", // wrong sign + " 555555555", // starts with space "555555555", // missing plus sign "+1 555 555 555", // space after plus sign - "+1555 555 555", // space after plus sign "+1555 555 555", // space between numbers "+1555+555", // multiple plus signs "+1555555555555555", // too long "+115abc55", // non numeric characters in number part + "+1555555 ", // space after number ]; expect(validE164Numbers.every((number) => e164Number.safeParse(number).success)).toBe(true); diff --git a/deno/lib/types.ts b/deno/lib/types.ts index f82e1ac26..2b4868028 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -622,12 +622,16 @@ const ipv6Regex = const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/; +<<<<<<< HEAD <<<<<<< HEAD // based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address const hostnameRegex = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/; ======= // https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex from there allows spaces) +======= +// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces) +>>>>>>> 0c908749 (cleanup and missing files) const e164Regex = /^\+(?:[0-9]){6,14}[0-9]$/; >>>>>>> 84694186 (Added e164 validation) diff --git a/src/__tests__/string.test.ts b/src/__tests__/string.test.ts index 7cecae9ca..60148e7da 100644 --- a/src/__tests__/string.test.ts +++ b/src/__tests__/string.test.ts @@ -911,7 +911,7 @@ test("E.164 validation", () => { expect(e164Number.safeParse("+1555555").success).toBe(true); const validE164Numbers = [ - "+1555555", // min-length (7 + 1) + "+1555555", // min-length (7 digits + '+') "+15555555", "+155555555", "+1555555555", @@ -921,20 +921,21 @@ test("E.164 validation", () => { "+15555555555555", "+155555555555555", "+105555555555555", - "+100555555555555", // max-length (15 + 1) + "+100555555555555", // max-length (15 digits + '+') ]; const invalidE164Numbers = [ "", // empty "+", // only plus sign "-", // wrong sign + " 555555555", // starts with space "555555555", // missing plus sign "+1 555 555 555", // space after plus sign - "+1555 555 555", // space after plus sign "+1555 555 555", // space between numbers "+1555+555", // multiple plus signs "+1555555555555555", // too long "+115abc55", // non numeric characters in number part + "+1555555 ", // space after number ]; expect(validE164Numbers.every((number) => e164Number.safeParse(number).success)).toBe(true); diff --git a/src/types.ts b/src/types.ts index 8d2411e66..3e14cd543 100644 --- a/src/types.ts +++ b/src/types.ts @@ -611,18 +611,18 @@ let emojiRegex: RegExp; // faster, simpler, safer const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/; - const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/; // https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/; - // based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address + const hostnameRegex = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/; -// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex from there allows spaces) + +// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces) const e164Regex = /^\+(?:[0-9]){6,14}[0-9]$/; // simple From 5cbae6f59f1ca7e878d2c9e469cdf59cb3077c5c Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 16 May 2024 00:56:15 +0100 Subject: [PATCH 3/5] added documentation --- README.md | 14 ++++++++++++++ deno/lib/README.md | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/README.md b/README.md index 5c61272b9..a09c9dfbf 100644 --- a/README.md +++ b/README.md @@ -826,6 +826,20 @@ if (!env.success) { This is recommended over using `z.string().transform(s => JSON.parse(s))`, since that will not catch parse errors, even when using `.safeParse`. +### E.164 telephone numbers + +The z.string().e164() method can be used to validate international telephone numbers. + +```ts +const e164Number = z.string().e164(); + +e164Number.parse("+1555555"); // pass +e164Number.parse("+155555555555555"); // pass + +e164Number.parse("555555555"); // fail +e164Number.parse("+1 1555555"); // fail +``` + ## Numbers You can customize certain error messages when creating a number schema. diff --git a/deno/lib/README.md b/deno/lib/README.md index 5c61272b9..da2edb8e8 100644 --- a/deno/lib/README.md +++ b/deno/lib/README.md @@ -788,6 +788,7 @@ const ipv6 = z.string().ip({ version: "v6" }); ipv6.parse("192.168.1.1"); // fail ``` +<<<<<<< HEAD ### JSON The `z.string().json(...)` method parses strings as JSON, then [pipes](#pipe) the result to another specified schema. @@ -826,6 +827,22 @@ if (!env.success) { This is recommended over using `z.string().transform(s => JSON.parse(s))`, since that will not catch parse errors, even when using `.safeParse`. +======= +### E.164 telephone numbers + +The z.string().e164() method can be used to validate international telephone numbers. + +```ts +const e164Number = z.string().e164(); + +e164Number.parse("+1555555"); // pass +e164Number.parse("+155555555555555"); // pass + +e164Number.parse("555555555"); // fail +e164Number.parse("+1 1555555"); // fail +``` + +>>>>>>> cc17c188 (added documentation) ## Numbers You can customize certain error messages when creating a number schema. From 5f07271868c70a389032354ed2840b0fa3f061df Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Wed, 15 May 2024 21:20:19 -0700 Subject: [PATCH 4/5] Build deno --- deno/lib/README.md | 3 --- deno/lib/types.ts | 14 ++------------ 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/deno/lib/README.md b/deno/lib/README.md index da2edb8e8..a09c9dfbf 100644 --- a/deno/lib/README.md +++ b/deno/lib/README.md @@ -788,7 +788,6 @@ const ipv6 = z.string().ip({ version: "v6" }); ipv6.parse("192.168.1.1"); // fail ``` -<<<<<<< HEAD ### JSON The `z.string().json(...)` method parses strings as JSON, then [pipes](#pipe) the result to another specified schema. @@ -827,7 +826,6 @@ if (!env.success) { This is recommended over using `z.string().transform(s => JSON.parse(s))`, since that will not catch parse errors, even when using `.safeParse`. -======= ### E.164 telephone numbers The z.string().e164() method can be used to validate international telephone numbers. @@ -842,7 +840,6 @@ e164Number.parse("555555555"); // fail e164Number.parse("+1 1555555"); // fail ``` ->>>>>>> cc17c188 (added documentation) ## Numbers You can customize certain error messages when creating a number schema. diff --git a/deno/lib/types.ts b/deno/lib/types.ts index 2b4868028..6d07da182 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -551,11 +551,8 @@ export type ZodStringCheck = | { kind: "duration"; message?: string } | { kind: "ip"; version?: IpVersion; message?: string } | { kind: "base64"; message?: string } -<<<<<<< HEAD | { kind: "json"; message?: string }; -======= | { kind: "e164"; message?: string }; ->>>>>>> 84694186 (Added e164 validation) export interface ZodStringDef extends ZodTypeDef { checks: ZodStringCheck[]; @@ -614,26 +611,19 @@ let emojiRegex: RegExp; // faster, simpler, safer const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/; - const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/; // https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/; - -<<<<<<< HEAD -<<<<<<< HEAD // based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address + const hostnameRegex = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/; -======= -// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex from there allows spaces) -======= + // https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces) ->>>>>>> 0c908749 (cleanup and missing files) const e164Regex = /^\+(?:[0-9]){6,14}[0-9]$/; ->>>>>>> 84694186 (Added e164 validation) // simple // const dateRegexSource = `\\d{4}-\\d{2}-\\d{2}`; From 55290ee1b079b33a0dff2f919f0cd31d63cb36b3 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Wed, 15 May 2024 21:24:57 -0700 Subject: [PATCH 5/5] Fix tests --- deno/lib/types.ts | 10 +++++----- src/types.ts | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/deno/lib/types.ts b/deno/lib/types.ts index 6d07da182..18b06f8ef 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -551,7 +551,7 @@ export type ZodStringCheck = | { kind: "duration"; message?: string } | { kind: "ip"; version?: IpVersion; message?: string } | { kind: "base64"; message?: string } - | { kind: "json"; message?: string }; + | { kind: "json"; message?: string } | { kind: "e164"; message?: string }; export interface ZodStringDef extends ZodTypeDef { @@ -1039,14 +1039,14 @@ export class ZodString extends ZodType { }); } } else if (check.kind === "e164") { - if (!e164Regex.test(input.data)) { - ctx = this._getOrReturnCtx(input, ctx); - addIssueToContext(ctx, { + if (!e164Regex.test(input)) { + issues = issues || []; + issues.push({ + input, validation: "e164", code: ZodIssueCode.invalid_string, message: check.message, }); - status.dirty(); } } else { util.assertNever(check); diff --git a/src/types.ts b/src/types.ts index 3e14cd543..4c8c332df 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1039,14 +1039,14 @@ export class ZodString extends ZodType { }); } } else if (check.kind === "e164") { - if (!e164Regex.test(input.data)) { - ctx = this._getOrReturnCtx(input, ctx); - addIssueToContext(ctx, { + if (!e164Regex.test(input)) { + issues = issues || []; + issues.push({ + input, validation: "e164", code: ZodIssueCode.invalid_string, message: check.message, }); - status.dirty(); } } else { util.assertNever(check);