I'm using the following code for validating email address which are present in an array. But after successfully validating first email address in an array, it is always returning false for next email address. May I know why it is behaving like that?
public static bool IsValidEmailID(string email)
{
string MatchEmailPattern =
@"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
+ @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
+ @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
+ @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";
Regex reStrict = new Regex(MatchEmailPattern);
return reStrict.IsMatch(email);
}
Update : The following code is getting email address from windows form text box:
String[] EmailArr = txtEmailID.Text.Split(new char[]{','},StringSplitOptions.RemoveEmptyEntries);
for(int i = 0; i < EmailArr.Length; i++)
{
MessageBox.Show(IsValidEmailID(EmailArr[i])+" "+EmailArr[i]);
}
IsValidEmailIDmethod also, and in addition the two first lines of the array? The problem is not with this code. I tried it on an array of valid e-mails, and it returned true for all of them.