Q:

Angular pattern Validator is not working as expected

To allow only emails with TLD (ending with .de or .com) I want to use the following pattern:
^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-zA-Z]{2,4}$

I tested this regular expression on regexr.com a couple of times and it worked good, for example it did not match with test@test.
But the Angular Validator says no error for test@test with this pattern Validator:
Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-zA-Z]{2,4}$')

How is that possible?

A:

You have to escape the backslash, since it's a string.
'^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-zA-Z]{2,4}$'

