fix: Allow single-label domains and missing dots (#25899)
This commit is contained in:
@@ -55,13 +55,14 @@ describe("excludeOrRequireEmailSchema", () => {
|
||||
it("accepts long multi-level domains", () => {
|
||||
expect(parse("example.co.uk.test.com").success).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts single-label domains and missing dots", () => {
|
||||
expect(parse("example").success).toBe(true);
|
||||
expect(parse("@example").success).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("invalid inputs", () => {
|
||||
it("rejects single-label domains and missing dots", () => {
|
||||
expect(parse("example").success).toBe(false);
|
||||
expect(parse("@example").success).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects invalid TLD lengths", () => {
|
||||
expect(parse("example.c").success).toBe(false);
|
||||
|
||||
@@ -970,7 +970,7 @@ export const excludeOrRequireEmailSchema = z.string().superRefine((val, ctx) =>
|
||||
// Accept forms: domain-only, `@domain`, or `local@domain`
|
||||
// - Domain labels: alnum, hyphens allowed internally, no leading/trailing hyphen
|
||||
// - Require at least one dot and end with an alpha TLD of length ≥2
|
||||
const EMAIL_OR_DOMAIN_PATTERN = /^(?:[a-z0-9._+'-]+@|@)?(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;
|
||||
const EMAIL_OR_DOMAIN_PATTERN = /^(?:[a-z0-9._+'-]+@|@)?(?:[a-z]{2,}|(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,})$/i;
|
||||
|
||||
const isValid = allDomains.every((entry) => EMAIL_OR_DOMAIN_PATTERN.test(entry));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user