-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8bb3e3e
commit 8ec0a1c
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { zEmail } from '../zod/zod.shared.schemas' | ||
import { zIsValid } from '../zod/zod.util' | ||
import { SIMPLE_EMAIL_REGEX } from './regex' | ||
|
||
test.each(['[email protected]', '[email protected]', '[email protected]'])( | ||
'email valid %', | ||
s => { | ||
expect(s).toMatch(SIMPLE_EMAIL_REGEX) | ||
// cross-check with Zod | ||
expect(zIsValid(s, zEmail)).toBe(true) | ||
}, | ||
) | ||
|
||
test.each([ | ||
'kirill@@naturalcycles.com', | ||
'[email protected]', | ||
'kirill@naturalcyclescom', | ||
'kirillnaturalcycles.com', | ||
'@kirillnaturalcycles.com', | ||
'[email protected]@', | ||
])('email invalid %', s => { | ||
expect(s).not.toMatch(SIMPLE_EMAIL_REGEX) | ||
// cross-check with Zod | ||
expect(zIsValid(s, zEmail)).toBe(false) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Simple, intentionally not exhaustive regex to match an email address. | ||
* | ||
* Source: https://regexr.com/3e48o | ||
*/ | ||
export const SIMPLE_EMAIL_REGEX = /^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/ |