Email Address Validation To Window Application C#

Email Address Validation To Window Application C#

Email Address Enter To Textbox Validation Check Suppose Error Occur Open Popup Using window Application C#.

                                DEMO



                           
                          C# CODING


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Email : Form
    {
        public Email()
        {
            InitializeComponent();
        }    
                  

      private void txtEmailId_Validating(object sender, CancelEventArgs e)
        {
            System.Text.RegularExpressions.Regex RegEmail =

              new System.Text.RegularExpressions.Regex(@"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");

            if (txtEmailId.Text.Length > 0 && txtEmailId.Text.Trim().Length != 0)
            {
                if (!RegEmail.IsMatch(txtEmailId.Text.Trim()))
                {

                    MessageBox.Show("Invalid Email Id", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    txtEmailId.SelectAll();

                    //e.Cancel = true;

                }
            }
        }
    }
}


First - Add New Form - Add TextBox From ToolBox - Change The Id




Next - TextBox Event - Click - Double Click Validating Button







Next - Invalid Email Id Enter Check Regular Expression Condition 






Next - Run[F5] - The Program  Enter Email Id - Invalid Enter Error Box Open










0 comments:

Post a Comment