Files
30-seconds-of-code/snippets/validateEmail.md
2017-12-17 17:55:51 +02:00

450 B

validateEmail

Returns true if the given string is a valid email, false otherwise.

Use a regular expression to check if the email is valid. Returns true if email is valid, false if not.

const validateEmail = str =>
  /^(([^<>()\[\]\\.,;:\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,}))$/.test(str);
// validateEmail(mymail@gmail.com) -> true