I want to validate a string which can be an email or multiple emails separated by commas.
For example:
bill.gates@hotmail.com -> TRUE
bill -> FALSE
try this
function validateEmails(string) {
var regex = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
var result = string.replace(/\s/g, "").split(/,|;/);
for(var i = 0;i < result.length;i++) {
if(!regex.test(result[i])) {
return false;
}
}
return true;
}
accepts both comma and semicolon as separator, change that if you want only comma as separator