Skip to content

Instantly share code, notes, and snippets.

@ianoxley
Created August 1, 2011 14:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianoxley/1118247 to your computer and use it in GitHub Desktop.
Save ianoxley/1118247 to your computer and use it in GitHub Desktop.
jQuery Validation Plugin: Multiple Email Address Validation
// Edited / adapted from http://forum.jquery.com/topic/jquery-validate-comma-seperated-multiple-emails-validation#14737000002179275
jQuery.validator.addMethod("multiemail", function (value, element) {
if (this.optional(element)) {
return true;
}
var emails = value.split(','),
valid = true;
for (var i = 0, limit = emails.length; i < limit; i++) {
value = emails[i];
valid = valid && jQuery.validator.methods.email.call(this, value, element);
}
return valid;
}, "Invalid email format: please use a comma to separate multiple email addresses.");
@masudcse05
Copy link

masud

@hasghari
Copy link

Thanks for this custom validator. I made one additional tweak on line 11:

value = jQuery.trim(emails[i])

@brightmohan
Copy link

How do I use this plugin in my javascript file?

@bdougie
Copy link

bdougie commented Aug 12, 2014

can you share the code that calls the jquery method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment