0% found this document useful (0 votes)
28 views

Protected Void Object False: Eventargs

The document describes code for validating email addresses entered into a registration form. It includes labels, text boxes, and buttons to collect an email and submit the form. On form submit, it calls a CheckEmail function that uses a regular expression to validate the email format. If invalid, it displays an error message label in red text and empties the text box. If valid, it performs registration actions like inserting into a database.

Uploaded by

Stanly Jones
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Protected Void Object False: Eventargs

The document describes code for validating email addresses entered into a registration form. It includes labels, text boxes, and buttons to collect an email and submit the form. On form submit, it calls a CheckEmail function that uses a regular expression to validate the email format. If invalid, it displays an error message label in red text and empties the text box. If valid, it performs registration actions like inserting into a database.

Uploaded by

Stanly Jones
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Design this page with label1 (text: e-mail), textbox1, button1(text:register), label2.

Label2 is just for displaying error message (Invalid email address in red colour). protected void Page_Load(object sender, EventArgs e) { Label2.Visible = false; } Set the visible of the label2 to false during run time. protected void Button1_Click(object sender, EventArgs e) { if (CheckEmail(TextBox7.Text)) { //process anything like inserting the email address in database. } else { Label2.Visible = true; Label2.ForeColor = System.Drawing.Color.Red; Label2.Text = "Inavalid email"; TextBox1.Text = ""; TextBox1.Focus(); } } Here CheckEmail is function name.

private bool CheckEmail(string EmailAddress) { string strPattern = "^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[azA-Z]{2,9})$"; if (System.Text.RegularExpressions.Regex.IsMatch(EmailAddress, strPattern)) { return true; } return false; }

Complete coding: using System; using System.Data;

using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using System.Drawing; public partial class MasterPage : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { Label2.Visible = false; } protected void Button1_Click(object sender, EventArgs e) { if (CheckEmail(TextBox7.Text)) { //process anything like inserting the email address in database. } else { Label2.Visible = true; Label2.ForeColor = System.Drawing.Color.Red; Label2.Text = "Inavalid email"; TextBox1.Text = ""; TextBox1.Focus(); } } private bool CheckEmail(string EmailAddress) { string strPattern = "^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[azA-Z]{2,9})$"; if (System.Text.RegularExpressions.Regex.IsMatch(EmailAddress, strPattern)) { return true; } return false; } }

You might also like