Hi,
I am working with win-forms in visual studio in c#. I have designed a label in cs file in dynamically to match an email id pattern.
The label will be displayed in red color when the email id text box is not matching with pattern. And that displayed text will be visible though we re enter an email id in correct format.
I'm giving my code snippest.i called this method in textbox leave event.
public void verification()
{
Label emailalert = new Label();
panel1.Controls.Add(emailalert);
emailalert.Location = new System.Drawing.Point(260, 92);
emailalert.Size = new Size(200, 25);
//emailalert.ForeColor = System.Drawing.Color.Red;
string verify = Convert.ToString(textBox6.Text);
string pattern = "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";
Match match = Regex.Match(verify, pattern, RegexOptions.IgnoreCase);
if (!match.Success)
{
emailalert.ForeColor = System.Drawing.Color.Red;
emailalert.Text = "Entered email id is not in correct format";//Here the text should be invisible when pattern matches
}
}
No comments:
Post a Comment