Check Email using RegEx class.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under Visual Studio category on | Points: 40 | Views : 315
using System.Text.RegularExpressions;
private const string _iPattern = @"^[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]$";

public bool CheckEmailAddress(string EmailAddress)
{
bool Check = false;

Regex RegEx = new Regex(_iPattern);
Check = RegEx.IsMatch(EmailAddress);
return Check;
}

bool is_valid_email_id1 = CheckEmailAddress("abc@xyz.com"); //true
bool is_valid_email_id2 = CheckEmailAddress("abcxyz.com"); //false
bool is_valid_email_id3 = CheckEmailAddress("a@bcxyz"); //false

Comments or Responses

Login to post response