Email REGEX checking on email format

Viewed 157
export const REGEX_EMAIL = /^\S+@\S+\.\S+$/;

I want to check email format like
email : Heythere123@something.com // passed
but 
email: Heythere123@something.com2222 // should not pass
email: Heythere123@something.com#$@! // shuuld not pass


//but from now they pass How i add the REGX email format

2 Answers

I had created this function for my projects:

 isEmailValid(email) {
       const regularExpression = /[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]{2,3}/;
       return regularExpression.test(email);
  },

I use this site to test them: https://regexr.com/

Using \S is a very broad match and matches any non whitespace char.

You can make the pattern slightly more specific using a character class at the end [a-z]{2,}$ and not match an @ sign twice using a negated character class [^@\s]

^[^@\s]+@[^@\s]+\.[a-z]{2,}$

Regex demo

Related