Quantcast
Channel: How can I validate an email address using a regular expression? - Stack Overflow
Viewing all articles
Browse latest Browse all 89

Answer by Carli Beeli for How can I validate an email address using a regular expression?

$
0
0

For Angular2 / Angular7 I use this pattern:

emailPattern = '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+[.]+[a-zA-Z0-9-.]+(\\s)*';private createForm() {  this.form = this.formBuilder.group({    email: ['', [Validators.required, Validators.pattern(this.emailPattern)]]  });}

It also allows for extra spaces at the end, which you should truncate before sending it to the backend, but some users, especially on mobile are easy to mistakenly add a space at the end.


Viewing all articles
Browse latest Browse all 89

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>