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?
You have to escape the backslash, since it's a string.
'^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-zA-Z]{2,4}$'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With