Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 6 email regex [duplicate]

Tags:

regex

angular

I want to validate all email inputs on my app with regex. But there is a problem, all the regex I have found allow emails with no TLD. I want a regex that can help me reject emails such as testing@testing,

Examples:

  • [email protected] should be valid
  • [email protected] should be valid
  • testing@testing should not be valid

The current regex I use is : ^([a-zA-Z0-9_-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$

But it accepts testing@testing for example, and that is not what I want. How would I go about validating emails and rejecting ones without TLD

like image 906
Node_Ninja Avatar asked Aug 28 '26 18:08

Node_Ninja


1 Answers

This is the regex which does what you want:

[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\\.[a-z]{2,3}

like image 63
Sachin Jagtap Avatar answered Aug 31 '26 06:08

Sachin Jagtap



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!