[Fixed] Angular email validation pattern


What can be the pattern for email validation with strict error even if I type – "[email protected]".

 emailPattern = '^[a-z0-9._%+-][email protected][a-z0-9.-]+\\.[a-z]{2,4}$';  
 initLoginForm() {
    this.loginForm = this.formBuilder.group({
      email: ['', Validators.compose([Validators.required, Validators.pattern(this.emailPattern)])],
      password: ['', Validators.required]

But it does not error if I type ".co" instead of ".com".
Can someone please tell what should be the regex exp to have this error too.


Its because regexp allow it .[a-z]{2,4}$ this means that user can type from 2 to 4 characters in the end after dot.

Regexp will test only patterns but it does not have any other logic, so if your expectation is to make sure that domain exists then i would not recommend to do it.

This is why many platforms have email validation so user need to validate their email before account become active.

Leave a Reply

(*) Required, Your email will not be published