This verification method works fine. I created an ArrayList array and loop through the array. I call your method to check email. Here is an example loop:
bool result = false; ArrayList emails = new ArrayList(); emails.Add(" test@test.org "); emails.Add("Hello.com"); emails.Add(" hello@hotmail.com "); foreach (string email in emails) { result = IsValidEmailID(email); }
The result of the first time is true, the second is false, and the third is true. What collection are you using? Perhaps all emails except the first are invalid ....?
UPDATE:
I tested your code
string textEmail = " test@test.org ,Hello.com, hello@hotmail.com "; String[] EmailArr = textEmail.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < EmailArr.Length; i++) { Console.WriteLine(IsValidEmailID(EmailArr[i]) + " " + EmailArr[i]); }
Your split works well. The only thing I can offer is to trim the string before validation. Sometimes text cells have extra spaces, which can cause problems.
IsVAludEmailID(EmailArr[i].Trim())
source share