Link to home
Start Free TrialLog in
Avatar of skij
skijFlag for Canada

asked on

JavaScript/REGEX: Validate email addresses separated by commas

I use this JavaScript code to validate an email address:
var e = 'email@example.com';
if(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(e) == false) alert('Fail');

Open in new window


How can I test to see if any email addresses, separated by commas, are invalid?

For example, this should pass:
test@example.com, xyy@example.com, hello@example.com

But this should fail:
test@example.com, xyy, hello@example.com
SOLUTION
Avatar of Russ Suter
Russ Suter

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of skij

ASKER