-
Notifications
You must be signed in to change notification settings - Fork 0
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
R. S. Doiel
committed
Dec 12, 2024
1 parent
c2f1637
commit d5af0f5
Showing
5 changed files
with
35 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const EMAILPattern = '^(?:"?([^"]*)"?\\s)?(?:<?(.+@[^>]+)>?)$'; | ||
export const reEMAIL = new RegExp(EMAILPattern); | ||
|
||
export function normalizeEMAIL(email: string): string { | ||
return email.trim().replaceAll(/\s+/g,'').trim(); | ||
} | ||
|
||
export function validateEMAIL(email: string): boolean { | ||
const normalized = normalizeEMAIL(email); | ||
return reEMAIL.test(normalized); | ||
} |
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,20 @@ | ||
import { assertEquals } from "@std/assert"; | ||
|
||
import { normalizeEMAIL, validateEMAIL } from './email.ts'; | ||
|
||
const varified_ids: string[] = [ | ||
"a@localhost", | ||
"a.b@localhost", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
]; | ||
|
||
for (let id of varified_ids) { | ||
// Normalize | ||
let normalized = normalizeEMAIL(id); | ||
console.log(`Normalized Email: ${normalized}`); | ||
// Validate | ||
assertEquals(validateEMAIL(id), true); | ||
} | ||
|
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
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