Files
30-seconds-of-code/snippets/validate-email.md
2017-12-14 11:23:21 +02:00

379 B

Validate email

Use a regular experssion 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);
// isemail(mymail@gmail.com) -> true