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,372
  • 4
  • 34
  • 52
  • The regex from [this](http://stackoverflow.com/a/8829363/247893) thread [works fine](http://regex101.com/r/aR5tG1)? – h2ooooooo Feb 06 '14 at 16:24
  • don't, see http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address?rq=1 – Fredrik Pihl Feb 06 '14 at 16:24
  • Just use a char search to check for @.there was a top level domain with an mx record at one point – user1937198 Feb 06 '14 at 16:30
  • As input to your regex, are you sending a string of text including a possible email address, or just the potential email address itself. – Jon Senchyna Feb 06 '14 at 18:55

3 Answers3

1

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

Donnie Rock
  • 552
  • 1
  • 14
  • 27
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
  • 58,320
  • 7
  • 77
  • 95
  • 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,867
  • 2
  • 26
  • 46