Protected Void Object False: Eventargs
Protected Void Object False: Eventargs
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; }
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; } }