0

I searched this site and found many threads that deal with this topic. But don't know why none of them realized that email formats vary a lot and not limited to xxx@ddd.com or something like this as for example xxxx@ddddd.rr.com is valid email address and so is xxx@ddd.museum . I tried almost all regular expressions that can be found for validating emails, none worked for this validation. Then there are emails with .info, .museum, etc.

I am very poor at regular expressions. Just wondering if someone can write a very broad express that checks for "at least one @ and one or more dots, no comma). I understand it will not work perfectly but at least it will not reject valid email addresses.

Allen King
  • 2,200
  • 3
  • 30
  • 47

3 Answers3

1

I though this could works: \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]+\b

Donnie Rock
  • 567
  • 1
  • 14
  • 26
0

My best bet is \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*. This rocks.

Its official Microsoft's email regex, which i got from my visual studio ultimate 2013 :)

Amit Joki
  • 56,285
  • 7
  • 72
  • 91
  • Please look at this: http://en.wikipedia.org/wiki/Email_address#Valid_email_addresses dot is not mandatory in the domain part, `myemail@com` is a valid address. – Toto Feb 07 '14 at 09:31
0

Since your question seems to be focused on capturing what comes after the '@', I'll simply post the regex for that. The following should work for you:

@((\w+(-+\w+)*\.)+\w+(-+\w+)*\b

To break it down, this will capture:

  1. @
  2. At least one repetition of a "word" (that can include, but doesn't begin or end with a dash) followed by a dot: ((\w+(-+\w+)*)\.)+
  3. A final "word" (again, that can include, but doesn't begin or end with a dash): \w+(-+\w+)*\b

To break down the "word" regex \w+(-+\w+)*), I'm capturing:

  1. At least one alpha-numeric character \w+
  2. Any number of the following:
    1. At least one dash -+ followed by
    2. At least one alpha-numeric character \w+
Jon Senchyna
  • 7,619
  • 2
  • 24
  • 45