Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Oh my God. People! I hate Net.Mail. Regex are best of the best.</p> <p>Take a look at this code and you'll see that I'm right.</p> <pre><code>public const string Email4 = @"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&amp;'\*\+/=\?\^`\{\}\|~\w])*)(?&lt;=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$"; private static Regex regex; private static void Main(string[] args) { var regex = new Regex(Email4, RegexOptions.Compiled); var list = new List&lt;string&gt;(); var str = new[] { // Success email "mkyong@yahoo.com", "mkyong-100@yahoo.com", "mkyong.100@yahoo.com", "mkyong111@mkyong.com", "mkyong-100@mkyong.net", "mkyong.100@mkyong.com.au", "mkyong@1.com", "mkyong@gmail.com.com", "mkyong+100@gmail.com", "mkyong-100@yahoo-test.com", //Fail email "mkyong", "mkyong@.com.my", "mkyong123@gmail.a", "mkyong123@.com", "mkyong123@.com.com", ".mkyong@mkyong.com", "mkyong()*@gmail.com", "mkyong@%*.com", "mkyong..2002@gmail.com", "mkyong.@gmail.com", "mkyong@mkyong@gmail.com", "mkyong@gmail.com.1a", // Test Email project "mkyong@gmail.com", // success "mkyong_sdf@gmail.com", // success "mkyong_@gmail.com", // fail // success "test+test@gmail.com" }; list = str.ToList(); foreach (string x in list) { foreach (string st in ParseEmail(x)) { Console.WriteLine(st); } } Console.ReadKey(); } private static IEnumerable&lt;string&gt; ParseEmail(string str) { regex = new Regex(email_pattern, RegexOptions.Compiled); return regex.Matches(str).Count &gt; 0 ? (from x in regex.Matches(str).Cast&lt;Match&gt;() select (x.Value + "\t\t True\t" + Validate(str))) : new[] {str + "\t\t False\t"+Validate(str)}; } private static bool Validate(string email) { try { var address = new MailAddress(email); if (address.Address == email || address.Address.Equals(email)) return true; else return false; } catch (Exception exception) { return false; } } </code></pre> <p><em>> plzz..dont use regex..this is like cutting a tree with hammer – Fake.It.Til.U.Make.It</em></p> <p><strong>Now, all together on the pattern and take a look at the library. It turns out that Net.Mail missing even worse mistake than the pattern regex.</strong></p> <p>If someone is confronted with such a situation and will not need anything else, here I wrote myself.</p> <pre><code>@"^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9_]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$"; </code></pre> <p>For those who looking for a different solution <a href="http://fightingforalostcause.net/misc/2006/compare-email-regex.php" rel="nofollow">Email Regex compare</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload