Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am able to validate a single email id with single entry(as@yahoo.com). But i need to validate multiple email ids which can be comma separated or any other delimiter (as@yahoo.com,ad@yahoo.com)

What I have tried:

JavaScript
function validateEmail()
{  
     var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
     str = document.getElementById("txtContactEmail").value;
      var array = str.split(';');        
     for(var i =0;i<array.length;i++)
     { 
        var email = array[i];                
         if(!email.match(emailRegEx))
         {
            alert('The email address '+ ' "' +email+ '" '+ ' is invalid');
            return false;
        }
     }
     return true           
}
Posted
Updated 12-Dec-17 3:08am
v2

1 solution

OK. You just parse the string into an array of string, each with a single email address. Split the string on your delimiter, get the array of string back and then enumerate the array, sending each email address to your code that validates the address.

Your code appears to do that already, so what's the problem?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900