I am trying to return a value from a javascript function that checks whether a string of multiple email addresses contains valid emails:
validateEmail function:
validateEmail = function(email) {
var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
return re.test(email);
} // this returns true/false
var emails = ["[email protected]", "[email protected]"]
var emailResult = function(emails) {
var result;
emails.forEach(function(email) {
if(validateEmail(email.trim()) === false) {
result = false;
}
});
return result
}
If any of the emails are valid, I want emailResult to be equal to false. However, when I run console.log(emailResult), I just get a print out of my function's code. Can someone help?
Thanks!!
console.log(emailResult(emails))? (You also want to start withvar result = true;)