Created
August 1, 2011 14:35
-
-
Save ianoxley/1118247 to your computer and use it in GitHub Desktop.
jQuery Validation Plugin: Multiple Email Address Validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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."); |
Thanks for this custom validator. I made one additional tweak on line 11:
value = jQuery.trim(emails[i])
How do I use this plugin in my javascript file?
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
masud