Last active
December 22, 2023 11:16
-
-
Save PabloAballe/b83930ad065e36d7a7ac254979178408 to your computer and use it in GitHub Desktop.
Email Validation Snippet: Validates email addresses using regular expressions.
This file contains hidden or 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
| /** | |
| * Email Validation Snippet | |
| * Brief Description: Validates email addresses using regular expressions. | |
| * | |
| * Author: Pablo Aballe | |
| * Date: 2023-12-22 | |
| */ | |
| /** | |
| * Validates if an email address is valid. | |
| * @param {string} email - The email address to validate. | |
| * @returns {boolean} - Returns true if the email is valid, otherwise false. | |
| */ | |
| function validateEmail(email) { | |
| const regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/; | |
| return regex.test(email); | |
| } | |
| // Usage Example | |
| console.log(validateEmail("[email protected]")); // true | |
| console.log(validateEmail("example@emai")); // false | |
| // Additional Notes: | |
| // The regular expression used here is basic and may not cover all valid email address cases according to the RFC 5322 standard. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment