-
Notifications
You must be signed in to change notification settings - Fork 195
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
johnsle
committed
Oct 2, 2024
1 parent
f98c812
commit a085ed1
Showing
3 changed files
with
10 additions
and
6 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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
export function validateEmailAddress(emailString: string): void { | ||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
if (!emailRegex.test(emailString)) { | ||
export function validateEmailAddress(emailString: string | null | undefined): void { | ||
const emailIsEmptyOrUndefined = emailString ? emailString.length <= 0 : true; | ||
const atIndex = emailString?.indexOf('@'); | ||
const periodIndexAfterAt = emailString?.indexOf('.', atIndex); | ||
|
||
if (emailIsEmptyOrUndefined || atIndex === -1 || periodIndexAfterAt === -1) { | ||
throw new Error('Input email address does not have the correct format.'); | ||
} | ||
} |
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