Skip to content

Instantly share code, notes, and snippets.

@codebubb
Created September 16, 2019 08:51
Show Gist options
  • Select an option

  • Save codebubb/13041193450108e85e72897424f688d3 to your computer and use it in GitHub Desktop.

Select an option

Save codebubb/13041193450108e85e72897424f688d3 to your computer and use it in GitHub Desktop.
Validate Emails with JavaScript
// 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