All,
Please see the following code pen
http://codepen.io/anon/pen/eJNMwJ
I am trying to pass an array of strings into my function called Validate email which iteratively checks over emails to see if they match the regex.
However this function does not seem to work for some reason.
The regex is correct
var validEmail = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
function validEmailList(emails) {
console.log("running test 2");
return emails.every(function (email) {
validEmail.test(email.trim());
});
};
emails = ['[email protected]', '[email protected]'];
$('.test1').append(validEmail.test("[email protected]"));
$('.test2').append(validEmailList(emails));
Nothing seems to be returned from the function, I am expecting a boolean.
The function you pass to every
also has to return
something.
function validEmailList(emails) {
console.log("running test 2");
return emails.every(function (email) {
return validEmail.test(email.trim());
});
};
Although if you use arrow syntax, the return
is implied:
function validEmailList(emails) {
return emails.every( email => validEmail.test(email.trim()) );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With