Validation in e-mail in c#

Hey frnds, if you want to make validation in e-mail text box in C#.net, then you can just validate it by following code:
(instead of  TEXTBOX, you should write your text box name )

 string pattern = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|" +
                @"0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z]" +
                @"[a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";

            System.Text.RegularExpressions.Match match =
                Regex.Match(txtemail.Text.Trim(), pattern, RegexOptions.IgnoreCase);

            if (match.Success == false)
            {
                errorProvider1.SetError(TEXTBOX, "Invalid E-mail");
                txtemail.Focus();
                return 0;
            }

Popular Posts