0

I'd like to validate an email address input using the following regex:

^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$

However, it doesn't match an email in this format test@test.test-test.fr while it should be matched.

Could someone can get me a hint, where the problem is?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user3049045
  • 111
  • 1
  • 1
  • 5
  • Which regex group specifically is supposed to match `.test-test`, do you think? And, does it really match? – BalusC Dec 02 '13 at 16:44
  • This question is a duplicate. See [Using a regular expression to validate an email address](http://stackoverflow.com/q/201323/1497596). – DavidRR Dec 02 '13 at 21:31
  • Also see: [How to Find or Validate an Email Address](http://www.regular-expressions.info/email.html). – DavidRR Dec 02 '13 at 21:43

1 Answers1

2

This should work :

^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[A-Za-z]{2,})$

The problem was the dash in the second part of the domain, it didn't matched the original pattern.

Julien Rouvier
  • 316
  • 2
  • 8