Validate email address in C#

In this blog we will know how to validate email address in Csharp.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Email_validation._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
     <asp:TextBox runat="server" ID="txtemail"></asp:TextBox><br />
        <asp:Button runat="server" ID="Validate"  Text="Validate Email id"
            onclick="Validate_Click" />
        <asp:Label ID="lbl_message" runat="server" Font-Bold="True"

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;

namespace Email_validation
    public partial class _Default : System.Web.UI.Page

        private void ValidateEmail()
            string email = txtemail.Text;
            Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
            Match match = regex.Match(email);
            if (match.Success)
                lbl_message.Text=email + " is Valid Email Address";  
                lbl_message.Text = email + " is Invalid Email Address";
        protected void Validate_Click(object sender, EventArgs e)





Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now