From f818bc4782c0ab9d26a555f2ba862d5a33e0fc0d Mon Sep 17 00:00:00 2001 From: Sean Ferguson Date: Mon, 11 Mar 2024 16:02:19 -0400 Subject: [PATCH] fix(type): require tld for email addresses --- packages/type/src/validator.ts | 2 +- packages/type/tests/validation.spec.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/type/src/validator.ts b/packages/type/src/validator.ts index 1d429c8a1..80aae846d 100644 --- a/packages/type/src/validator.ts +++ b/packages/type/src/validator.ts @@ -45,7 +45,7 @@ export type AfterDate = ValidatorMeta<'afterDate', [T]>; export type BeforeNow = ValidatorMeta<'beforeNow'>; export type AfterNow = ValidatorMeta<'afterNow'>; -export const EMAIL_REGEX = /^\S+@\S+$/; +export const EMAIL_REGEX = /^\S+@\S+\.\S+$/; export type Email = string & Pattern; /** diff --git a/packages/type/tests/validation.spec.ts b/packages/type/tests/validation.spec.ts index 256648e1e..4b96425b9 100644 --- a/packages/type/tests/validation.spec.ts +++ b/packages/type/tests/validation.spec.ts @@ -22,9 +22,10 @@ test('email', () => { expect(is('@')).toBe(false); expect(validate('peter@example.com')).toEqual([]); - expect(validate('nope')).toEqual([{ path: '', code: 'pattern', message: `Pattern ^\\S+@\\S+$ does not match`, value: 'nope' }]); - expect(validate('nope@')).toEqual([{ path: '', code: 'pattern', message: `Pattern ^\\S+@\\S+$ does not match`, value: 'nope@' }]); - expect(validate('@')).toEqual([{ path: '', code: 'pattern', message: `Pattern ^\\S+@\\S+$ does not match`, value: '@' }]); + expect(validate('nope')).toEqual([{ path: '', code: 'pattern', message: `Pattern ^\\S+@\\S+\\.\\S+$ does not match`, value: 'nope' }]); + expect(validate('nope@')).toEqual([{ path: '', code: 'pattern', message: `Pattern ^\\S+@\\S+\\.\\S+$ does not match`, value: 'nope@' }]); + expect(validate('nope@gmail')).toEqual([{ path: '', code: 'pattern', message: `Pattern ^\\S+@\\S+\\.\\S+$ does not match`, value: 'nope@gmail' }]); + expect(validate('@')).toEqual([{ path: '', code: 'pattern', message: `Pattern ^\\S+@\\S+\\.\\S+$ does not match`, value: '@' }]); }); test('minLength', () => {