вторник, 20 апреля 2010 г.

jQuery Validation plugin - multiemail

Вчера пикрутил jQuery Validation plugin. Замечательная вещь!
Но встал вопрос валидации списка из нескольких email-адрессов... и тут мне попался
замечательный скрипт расширяющий функциональность jQuery Validation plugin - MultipleEmail:


  1. jQuery.validator.addMethod("multiemail", function(value, element) {
  2.     if (this.optional(element)) // return true on optional element
  3.       return true;
  4.     var emails = value.split( new RegExp( "\\s*,\\s*", "gi" ) );
  5.      valid = true;
  6.         for(var i in emails) {
  7.          value = emails[i];
  8.          valid=valid && jQuery.validator.methods.email.call(this, value, element);
  9.         }
  10.       return valid;
  11. }, 'The format for one or more emails is incorrect.');
* This source code was highlighted with Source Code Highlighter.

скрипт найден здесь
http://forum.jquery.com/topic/jquery-validation-calling-the-email-method-inside-a-custom-method