-
-
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.
Merge pull request #10 from gabriel-logan/brenoepics/enhance-validation
Enhance validation and documentation
- Loading branch information
Showing
3 changed files
with
49 additions
and
58 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
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,28 @@ | ||
/** | ||
* @example isEmail('[email protected]') true; | ||
* @example isEmail('foor@bar') false; | ||
* Validates if the given string is a valid email address. | ||
* | ||
* @example isEmail('[email protected]') // returns true; | ||
* @example isEmail('foo@bar') // returns false; | ||
* @example isEmail('[email protected]') // returns false, starts with a number. | ||
* @example isEmail('[email protected]') // returns false, domain starts with a number. | ||
* @example isEmail('[email protected]') // returns false, TLD starts with a number. | ||
* @example isEmail('[email protected]') // returns false, starts with consecutive dots. | ||
* @example isEmail('[email protected]') // returns false, local part contains consecutive dots. | ||
* @example isEmail('[email protected]') // returns false, domain contains consecutive dots. | ||
* @example isEmail('[email protected]') // returns false, domain contains consecutive dots before TLD. | ||
* @example isEmail('[email protected]..') // returns false, ends with consecutive dots. | ||
* @example isEmail('foo@@bar.com') // returns false, contains multiple @ symbols. | ||
* @example isEmail('[email protected]') // returns true, valid country code TLD. | ||
* @example isEmail('[email protected]') // returns false, domain repetition. | ||
* @example isEmail('[email protected]') // returns false, TLD too short. | ||
* @example isEmail('[email protected]') // returns false, starts with a special character. | ||
* @example isEmail('foo [email protected]') // returns false, contains spaces. | ||
* @example isEmail('foo@bar!com') // returns false, domain contains special characters. | ||
* @example isEmail('[email protected]') // returns false, local part contains special characters. | ||
* @example isEmail('[email protected]') // returns false, invalid TLD. | ||
* @description This function checks if the provided string is a valid email address according to the standard email formatting rules. It checks for the presence of an @ symbol, valid characters in the local part and domain, the absence of forbidden characters and patterns, and a valid top-level domain. | ||
* @param email The email address to validate. | ||
* @returns {boolean} True if the email address is valid, false otherwise. | ||
*/ | ||
function isEmail(email: string): boolean { | ||
if (typeof email !== "string") { | ||
|