Created
September 16, 2019 08:51
-
-
Save codebubb/13041193450108e85e72897424f688d3 to your computer and use it in GitHub Desktop.
Validate Emails with JavaScript
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
| // Really simple validation | |
| const simpleEmailRegex = /\S+@\S+\.\S+/; | |
| simpleEmailRegex.test('valid@email.com'); // true | |
| // Complex validation | |
| const complexEmailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | |
| complexEmailRegex.test('valid@email.com'); // true | |
| // Source: https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment