0

This is not working as I intended it to, regardless it's running my if clause even if my email format is: something like hello@gmail.com not sure what is wrong here.

        Regex RX = new Regex("^[a-zA-Z0-9]{1,20}@[a-zA-Z0-9]{1-20}.[a-zA-Z]{2,3}$");
        if (!RX.IsMatch(textEmail.Text))
        {
            MessageBox.Show("Email format is not correct");
        }

        else
        {
            MessageBox.Show("Email format is CORRECT");
        }

it should really run the else clause

hello world
  • 306
  • 1
  • 6
  • 28
  • `{1-20}` isn’t valid; the `-` should be a comma. But your regular expression is seriously wrong, too. I would recommend reading at least the Wikipedia page on what constitutes a valid e-mail address. – Ry- Aug 10 '13 at 00:38
  • 1
    The one I made, by the way, is *almost* right. `"((([a-zA-Z0-9!\#\$%&'*+\-\/=?^_\`{|}~]+|""([a-zA-Z0-9!\#\$%&'*+\-\/=?^_\`{|}~(),:;<>@\[\]\.]|\\[ \\""])*"")\.)*([a-zA-Z0-9!\#\$%&'*+\-\/=?^_\`{|}~]+|""([a-zA-Z0-9!\#\$%&'*+\-\/=?^_\`{|}~(),:;<>@\[\]\.]|\\[ \\""])*""))@((([a-zA-Z0-9]([a-zA-Z0-9]*(\-[a-zA-Z0-9]*)*)?\.)*[a-zA-Z]+|\[((0?\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])\.){3}(0?\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])\]|\[[Ii][Pp][vV]6(:[0-9a-fA-F]{0,4}){6}\]))"` – Ry- Aug 10 '13 at 00:40
  • 1
    ^? check out this page: http://www.regular-expressions.info/email.html – Smern Aug 10 '13 at 00:43
  • 1
    Specifically, [look at this for .NET](http://stackoverflow.com/a/407102/707111) – Ry- Aug 10 '13 at 00:43
  • http://ex-parrot.com/~pdw/Mail-RFC822-Address.html – I4V Aug 10 '13 at 00:45

0 Answers0