Email Id Address Validation For Asp.Net C# Using Regex Validation

Email Id Address Validation 


Enter Email Id Address in TextBox InValid Id Display Popup Error Message Using Asp.Net C#.

                                Download Coding

                                                Download

                                     DEMO



HTML CODING

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>   
        <asp:TextBox ID="txtEamilId" runat="server" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
   
    </div>
    </form>
</body>
</html>


                              C# CODING

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Windows.Forms;
using System.Text.RegularExpressions;

public partial class Battery : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }  
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
        Match match = regex.Match(txtEamilId.Text);
        if (!match.Success)
        {
            MessageBox.Show("Invalid EmailId", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        else {

            MessageBox.Show("Valid EmailId", "Valid", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }
    }
}


First Add New Form - Right Click- Solution Explorer - 

Add - Add Reference





Next - Add - Systems.Windows.Form  - OK






Next - Add TextBox From Toolbox - Id Change - AutoPostBack=True






Next - Double Click TextBoxes -  Add NameSpaces - Regex Coding For Email Validation





Next - Run[F5] - Verify Email ID





0 comments:

Post a Comment