ml2009, I seem to have it working within the confines of validating multiple email addresses within the plugin's reg exp. I made the validation check run only if the email length is greater than one...this takes care of the case when a user has a comma after the last email address (i.e., this prevents validation on the empty list or empty list with space). I also remove any whitespaces before or after each email address. Hopefully this will help:
email: function(value, element) { if(this.optional(element)) { return true; } var valid = true; var emails = value.split(","); for(var i in emails) { emailAddress = Trim(emails[i]); if (emailAddress.length > 0) { valid = valid && /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]| [\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\- \/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22) ((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f \x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0- \uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF \uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@ ((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d| [\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0- \uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900- \uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0- \uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-| \.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF \uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(emailAddress); } } return valid; }, // remove whitespaces at beginning and end of string function Trim(str){ while(str.charAt(0) == (" ") ) { str = str.substring(1); } while(str.charAt(str.length-1) == " " ) { str = str.substring(0,str.length-1); } return str; } On Mar 2, 10:06 am, ml2009 <mcl...@systemsview.biz> wrote: > Hi Stephan - thank you so much for your response. > > I keep trying, but being unsuccessful. I tried valid = valid &&, > (valid=valid) &&, and (valid == valid) &&, but I get a syntax error > reference in Firebug. I even tried declaring > > var valid = (value.length > 0); // make sure that value is not empty > > outside the for loop with a conditional statement if(valid==true) > inside the for loop, but I am sure I'm doing something wrong. could > you help again? > > jQuery.validator.addMethod("multiemail", function(value, element) > { > if (this.optional(element)) // return true on optional element > return true; > var emails = value.split(','); > valid = true; > for(var i in emails) { > value = emails[i]; > valid=valid && return > jQuery.validator.methods.email.call(this, > value, element); > } > } > return valid; > }, > jQuery.validator.messages.email // use default message > ); > > On Mar 2, 2:50 am, Stephan Veigl <stephan.ve...@gmail.com> wrote: > > > Hi, > > > you have the same error as above. > > > Having a return statement in a for loop will evaluate the first element > > only. > > If you want to validate all emails that's a logical AND conjunction of > > all single email validations. So you have to have some and function in > > your code as well. > > Try something like: > > > valid = true; > > for(var i in emails) { > > value = emails[i]; > > valid = valid && jQuery.validator.methods.email.call(this, value, > > element, param);} > > > return valid; > > > by(e) > > Stephan > > > 2009/3/2 ml2009 <mcl...@systemsview.biz>: > > > > Hello - wonder if you could help me. I tried another way to validate > > > multiple email addresses, but I still couldn't figure it out. on code > > > below, only the first email is validated. Any suggestions? > > > > jQuery.validator.addMethod("multiemail", function(value, element, > > > param) { > > > if (this.optional(element)) // return true on optional element > > > return true; > > > var emails = value.split(','); > > > > // for(var i = 0; i < emails.length; i++) { > > > for(var i in emails) { > > > value = emails[i]; > > > //alert(i); > > > return > > > jQuery.validator.methods.email.call(this, value, element, > > > param); > > > } > > > }, > > > jQuery.validator.messages.email // use default message > > > );- Hide quoted text - > > > - Show quoted text -