Email validation
-
How to perform email validaiton for windows applicaions in .net
-
How to perform email validaiton for windows applicaions in .net
Try this. I think it will help you. using System.Text.RegularExpressions; public static bool CheckEmailAddress(string strText) { //Validates the Email address string strPattern = @"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$"; return CheckRegExPattern(strPattern, strText.Trim()); } public static bool CheckRegExPattern(string strPattern, string strText) { return Regex.IsMatch(strText.Trim(), strPattern); }
-
How to perform email validaiton for windows applicaions in .net
You can also try this piece of code. Assumptions: 1. Your Windows form has a text box with the name txtEmailID 2. You have using System.Text.RegularExpressions at the top of your form. 3. Call the ValidateEmail function in the event where you want to validate the email id. private bool ValidateEmail() { bool checkFlag = false; string EmailID = txtEmailID.Text.Trim(); if (EmailID != "") { Regex regex = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"); Match match = regex.Match(EmailID); if (match.Length == EmailID.Length) { checkFlag = true; } else { MessageBox.Show("Enter a valid email-id"); checkFlag = false; txtEmailID.Focus(); } } else { MessageBox.Show("Enter Email ID"); txtEmailID.Focus(); } return checkFlag; } All the best. Siddharth P :)
-
Try this. I think it will help you. using System.Text.RegularExpressions; public static bool CheckEmailAddress(string strText) { //Validates the Email address string strPattern = @"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$"; return CheckRegExPattern(strPattern, strText.Trim()); } public static bool CheckRegExPattern(string strPattern, string strText) { return Regex.IsMatch(strText.Trim(), strPattern); }
HI Suamal, Thnak u for the help.It worked out. bye Uma
-
You can also try this piece of code. Assumptions: 1. Your Windows form has a text box with the name txtEmailID 2. You have using System.Text.RegularExpressions at the top of your form. 3. Call the ValidateEmail function in the event where you want to validate the email id. private bool ValidateEmail() { bool checkFlag = false; string EmailID = txtEmailID.Text.Trim(); if (EmailID != "") { Regex regex = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"); Match match = regex.Match(EmailID); if (match.Length == EmailID.Length) { checkFlag = true; } else { MessageBox.Show("Enter a valid email-id"); checkFlag = false; txtEmailID.Focus(); } } else { MessageBox.Show("Enter Email ID"); txtEmailID.Focus(); } return checkFlag; } All the best. Siddharth P :)
Hi Siddharth P, Thank u for the help. Uma