0

I have a very simple regexp to validate emails that looks like this:

^[\w.%+\-]+@[\w.\-]+\.[a-zA-Z]{2,16}$

When I enter this on the website as the regexp pattern, and "test@gmail.com" as the test string then it works as it should. If I try the string "test@gmail" it does not work because I don't want it to work with that.

But when I do this in TypeScript in validates even if the string is "test@gmail", not just "test@gmail.com", and I don't understand why.

Here is the relevant code snippet from TypeScript:

const regExp = new RegExp(`^[\\w.%+\-]+@[\\w.\-]+\.[a-zA-Z]{2,16}$`);
console.log(regExp.test(control.value));

control.value is the string "test@gmail".

It validates it, when it shouldn't.

Alex
  • 5,671
  • 9
  • 41
  • 81

0 Answers0