2
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

devAndDev
  • 57
  • 1
  • 5

2 Answers2

1

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/

Luca
  • 335
  • 3
  • 19
0

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

The fourth bird
  • 154,723
  • 16
  • 55
  • 70