jQuery.validate学习笔记

本文介绍如何使用jQuery的validate插件进行自定义验证方法。详细解释了如何添加自定义验证方法并通过不同方式调用这些方法。同时展示了如何根据不同条件启用验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


jQuery的validate验证功能十分强大,但是能够自定义验证方法更具有灵活性,所以我只是把自定义的说明一下。

添加自定义方法是使用jquery的jQuery.validator.addMethod方法,这个方法的完整定义如下:

[javascript]  view plain  copy
  1. jQuery.validator.addMethod("myValidateName"function(value, element, param) {  
  2. //myValidateName是自己定义的验证方法值  
  3. //value是指当前校验域的值  
  4. //element是指当前检验的域  
  5. //param是指在rules中设定的参数  
  6. },$.validator.format("xxx"));  


定义完之后,就可以通过在页面中声明和调用了。调用方法如下:

[javascript]  view plain  copy
  1. var validator = $("#formName").validate({//formName是form的名字  
  2.         submitHandler: function(form) { //提交时候调用的方法  
  3.             formSubmit();//调用成功后的处理函数  
  4.         } ,  
  5.         rules: {  
  6.             inputName1: "myValidateName",//如果只用一个验证方式的话,需要用引号标记上,而且这种方式是认为强制执行的,也就是一定要验证的  
  7.             inputName2: {//如果想使用多种验证方式,就需要使用花括号标记上,且逗号隔开,记住:最后一项不要有逗号  
  8.                 myValidateName1: true,//这种是强制执行的验证  
  9.                 myValidateName2: function(){if(某条件满足){return true;}else{return false;}},//这种根据条件判断要不要验证,更佳的灵活,用在多条件输入的时候极为方便  
  10.                 myValidateName3: [//使用方括号的是对于普通验证的更佳高级方法,这种方法也十分好用  
  11.                     function(){if(某条件满足){return true;}else{return false;}},//同上,验证条件判断,条件不满足,本验证就不生效  
  12.                     rangeValue1,//阈值控制值,这个值可以有任意多个,就看你的验证方法中是怎样声明的了  
  13.                     rangeValue2//阈值控制值  
  14.                 ]  
  15.             }  
  16.         },  
  17.         messages: {//验证到不合法的值的提示信息,如果不加这部分,就会执行你声明函数的时候的默认提示:“xxx”,就是在$.validator.format("xxx"));中声明的那个提示  
  18.             inputName1: "AAA",//这种写法是将所有验证不通过的全部提示AAA  
  19.             inputName2: {//这种就是更佳详细的提示,当然也可以使用上面的这种方式,无论myValidateName1,2还是3,只要有不通过的,都会提示同一条信息。  
  20.                 myValidateName1:"BBB",//但是如果详细些的提示,就需要用花括号标记上,并且内部用逗号隔开,且最后一个后面不能有逗号,就相当于使用数组的方式  
  21.                 myValidateName2:"CCC",  
  22.                 myValidateName3:"DDD"//这里后面不能有逗号了,不然在有些浏览器中会报错  
  23.             }  
  24.         },  
  25.   
  26.         errorPlacement: function(error, element) {//这里定义的是出错或者叫提示信息出现的位置  
  27.             error.insertAfter(element.parent().find('label:first'));//这句话的意思就是说,在验证不通过的那个标签上面的父节点开始向下找到第一个lable标签的后面,进行插入  
  28.         },  //就是这样,如下面:  
  29.             //<div>  
  30.             //  <lable>mylablename</lable> 这里是你定义的一个lable标签  
  31.             //  <input name="inputName1" type="text" />  
  32.             //</div>  
  33.             //如果验证不通过,那么就会从名字为inputName1的标签开始查找它的父标签,也就是div,然后再从div开始乡下找到第一个lable标签,就是mylablename那行,然后再在这行之后进行插入错误信息  
  34.             //执行之后,大概就是下面的样子:  
  35.             //<div>  
  36.             //  <lable>mylablename</lable> 这里是你定义的一个lable标签  
  37.             //  <lable>AAA</lable>这里是你验证不通过时的提示信息  
  38.             //  <input name="inputName1" type="text" />  
  39.             //</div>  
  40.           
  41.         success: function(label) {  
  42.             // set   as text for IE  
  43.             label.html(" ").addClass("ok");//这个就是如果验证通过了,就再在提示的那行lable标签中添加名字为ok的class类,用于改变css样式,至于名字随便起  
  44.         }  
  45.     });  


 下面举一个具体的例子

首先定义自己的验证方法,定义到myvalidate.js中,内容如下

[javascript]  view plain  copy
  1. $(document).ready(function(){  
  2. //验证IP地址  
  3.     jQuery.validator.addMethod("isIP"function(value, element, param) {    
  4.         if ( !this.depend(param, element) )//这个判断必须要加上,这个是判断是否要执行这个检测,就是对于rules中定义的isIP后面的条件的判断,如果不满足,就不再验证了  
  5.             return "dependency-mismatch";  //所以我说,这里必须要加上,其实也不是必须,但是这样会十分灵活,根据你的意愿让它到底何时验证  
  6.         var reg = new RegExp(getReg("ip"),"i");  //这里是一个正则表达式,具体是怎样的,就不列出来了,不懂的,自己百度一下正则表达式,很简单的  
  7.         return this.optional(element) || (reg.test(value)); //前面optional这部分我也不清楚是啥意思,但是看官方的js脚本都是加上的,那么咱们也照样加上,  
  8.                                                             //然后后面的这部分才是你真正的判断,注意:只有return false的时候,才会显示你的提示,如果返回的是true,那么就进入到了前面success函数哪里   
  9.     }, $.validator.format("not IP"));//这里就是如果没有通过验证要提示给用户的信息,显示位置由你声明调用的时候规定,在前文中有说明    
  10.       
  11. //验证在一定范围内的数值,这个例子就比较麻烦的那个,也就是前面说的是用方括号的那个  
  12.     jQuery.validator.addMethod("isMyRange"function(value, element, param) {   
  13.         if ( !this.depend(param[0], element) )//这里的param[0],就代表调用定义中的方括号中的第一个元素,如果按照前面myValidateName3的例子的话,它就是对应function那一行  
  14.             return "dependency-mismatch";  
  15.         var reg = new RegExp(getReg("integer65535"),"i");  //因为是判断数值,所以首先用正则表达式判断一下是不是数值,别验证半天,结果人家用户根本就没输入数值  
  16.         return this.optional(element) || (reg.test(value) && value >= param[1] && value <= param[2]);//这里的param[1]和param[2]就分别代表着第二和第三个元素,也就是rangeValue1和rangeValue2,那么这个验证的目的就是验证在rangeValue1和rangeValue2之间的数值    
  17.     }, $.validator.format("请输入 {1} 和 {2} 之间的数值"));//这里也需要注意,其中的{1}和{2}是分别代表你定义的rangeValue1和rangeValue2这两个值,其实,这里的{1}和{2}就是你在rulse中的那个方括号中定义的元素的下标,有过c语言或者程序开发的肯定再熟悉不过了,对,就是数组嘛  
  18. });  


下面在html页面中添加定义
比如我有个页面,叫test.html,内容如下:

[html]  view plain  copy
  1. <html>  
  2. <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script><!-- 先要包含jquery库 -->  
  3. <script type="text/javascript" src="js/jquery.validate.js"></script><!-- 还要包含jquery.validate库 -->  
  4. <script type="text/javascript" src="js/myvalidate"></script><!-- 最后才是你自己定义的库 -->  
  5. <script type="text/javascript">  
  6. $(document).ready(function(){//开始声明验证方法  
  7.       
  8.     var validator = $("#myform").validate({  
  9.         submitHandler: function(form) { //提交时候调用的方法  
  10.             formSubmit();  
  11.         } ,  
  12.         rules: {  
  13.             myipaddr: {  
  14.                 isIP: "#myradio_on:checked"//这里就是说当id为myradio_on的radio元素被选中的时候开始验证  
  15.             },  
  16.             mycount: {  
  17.                 isMyRange: [  
  18.                     "#myradio_on:checked",//同上  
  19.                     200,  
  20.                     800  
  21.                     ]  
  22.             }  
  23.         },  
  24.         //这里我省略掉了message,使用默认的提示,也就是我定义验证方法时给出的提示  
  25.         // the errorPlacement has to take the layout into account  
  26.         errorPlacement: function(error, element) {  
  27.             error.insertAfter(element.parent().find('label:first'));  
  28.         },  
  29.         // set new class to error-labels to indicate valid fields  
  30.         success: function(label) {  
  31.             // set   as text for IE  
  32.             label.html(" ").addClass("ok");  
  33.         }  
  34.     });  
  35. });  
  36.       
  37. </script>  
  38. <body>  
  39.     <form name="myform" id="myform" method="post" action="myaction.html">  
  40.     <div>  
  41.         <p>  
  42.             <label>是否验证</label><br/>  
  43.             <input type="radio" name="validate" id="validate_on"/>   
  44.                                               
  45.             <input type="radio" name="validate" id="myradio_off"/>   
  46.             <label for="myradio_off">算了</label>  
  47.         </p>  
  48.     </div>  
  49.     <div>  
  50.         <p>  
  51.             <label>IP验证</label><br/>  
  52.             <input type="text" name="myipaddr" id="myipaddr"/>   
  53.         </p>  
  54.     </div>  
  55.     <div>  
  56.         <p>  
  57.             <label>Count验证</label><br/>  
  58.             <input type="text" name="mycount" id="mycount"/>   
  59.         </p>  
  60.     </div>  
  61.     </form>  
  62. </body>  
  63. </html>  


 

到此一个完整的验证就出来了,你可以试一下,现在感觉确实很强大,如果有错误,希望大家指正,相互学习

下面附注一下jquery.validate.js文件中的内容,有部分有些改动,并非原版官方的,但是绝大多数都是一样的,大家可以看看,相信一定能学到很多东西

[javascript]  view plain  copy
  1. /* 
  2.  * jQuery validation plug-in 1.7 
  3.  * 
  4.  * http://bassistance.de/jquery-plugins/jquery-plugin-validation/ 
  5.  * http://docs.jquery.com/Plugins/Validation 
  6.  * 
  7.  * Copyright (c) 2006 - 2008 Jörn Zaefferer 
  8.  * 
  9.  * $Id: jquery.validate.js 6403 2009-06-17 14:27:16Z joern.zaefferer $ 
  10.  * 
  11.  * Dual licensed under the MIT and GPL licenses: 
  12.  *   http://www.opensource.org/licenses/mit-license.php 
  13.  *   http://www.gnu.org/licenses/gpl.html 
  14.  */  
  15.   
  16. (function($) {  
  17.   
  18. $.extend($.fn, {  
  19.     // http://docs.jquery.com/Plugins/Validation/validate  
  20.     validate: function( options ) {  
  21.   
  22.         // if nothing is selected, return nothing; can't chain anyway  
  23.         if (!this.length) {  
  24.             options && options.debug && window.console && console.warn( "nothing selected, can't validate, returning nothing" );  
  25.             return;  
  26.         }  
  27.   
  28.         // check if a validator for this form was already created  
  29.         var validator = $.data(this[0], 'validator');  
  30.         if ( validator ) {  
  31.             return validator;  
  32.         }  
  33.           
  34.         validator = new $.validator( options, this[0] );  
  35.         $.data(this[0], 'validator', validator);   
  36.           
  37.         if ( validator.settings.onsubmit ) {  
  38.           
  39.             // allow suppresing validation by adding a cancel class to the submit button  
  40.             this.find("input, button").filter(".cancel").click(function() {  
  41.                 validator.cancelSubmit = true;  
  42.             });  
  43.               
  44.             // when a submitHandler is used, capture the submitting button  
  45.             if (validator.settings.submitHandler) {  
  46.                 this.find("input, button").filter(":submit").click(function() {  
  47.                     validator.submitButton = this;  
  48.                 });  
  49.             }  
  50.           
  51.             // validate the form on submit  
  52.             this.submit( function( event ) {  
  53.                 if ( validator.settings.debug )  
  54.                     // prevent form submit to be able to see console output  
  55.                     event.preventDefault();  
  56.                       
  57.                 function handle() {  
  58.                     if ( validator.settings.submitHandler ) {  
  59.                         if (validator.submitButton) {  
  60.                             // insert a hidden input as a replacement for the missing submit button  
  61.                             var hidden = $("<input type='hidden'/>").attr("name", validator.submitButton.name).val(validator.submitButton.value).appendTo(validator.currentForm);  
  62.                         }  
  63.                         validator.settings.submitHandler.call( validator, validator.currentForm );  
  64.                         if (validator.submitButton) {  
  65.                             // and clean up afterwards; thanks to no-block-scope, hidden can be referenced  
  66.                             hidden.remove();  
  67.                         }  
  68.                         return false;  
  69.                     }  
  70.                     return true;  
  71.                 }  
  72.                       
  73.                 // prevent submit for invalid forms or custom submit handlers  
  74.                 if ( validator.cancelSubmit ) {  
  75.                     validator.cancelSubmit = false;  
  76.                     return handle();  
  77.                 }  
  78.                 if ( validator.form() ) {  
  79.                     if ( validator.pendingRequest ) {  
  80.                         validator.formSubmitted = true;  
  81.                         return false;  
  82.                     }  
  83.                     return handle();  
  84.                 } else {  
  85.                     validator.focusInvalid();  
  86.                     return false;  
  87.                 }  
  88.             });  
  89.         }  
  90.           
  91.         return validator;  
  92.     },  
  93.     // http://docs.jquery.com/Plugins/Validation/valid  
  94.     valid: function() {  
  95.         if ( $(this[0]).is('form')) {  
  96.             return this.validate().form();  
  97.         } else {  
  98.             var valid = true;  
  99.             var validator = $(this[0].form).validate();  
  100.             this.each(function() {  
  101.                 valid &= validator.element(this);  
  102.             });  
  103.             return valid;  
  104.         }  
  105.     },  
  106.     // attributes: space seperated list of attributes to retrieve and remove  
  107.     removeAttrs: function(attributes) {  
  108.         var result = {},  
  109.             $element = this;  
  110.         $.each(attributes.split(/\s/), function(index, value) {  
  111.             result[value] = $element.attr(value);  
  112.             $element.removeAttr(value);  
  113.         });  
  114.         return result;  
  115.     },  
  116.     // http://docs.jquery.com/Plugins/Validation/rules  
  117.     rules: function(command, argument) {  
  118.         var element = this[0];  
  119.           
  120.         if (command) {  
  121.             var settings = $.data(element.form, 'validator').settings;  
  122.             var staticRules = settings.rules;  
  123.             var existingRules = $.validator.staticRules(element);  
  124.             switch(command) {  
  125.             case "add":  
  126.                 $.extend(existingRules, $.validator.normalizeRule(argument));  
  127.                 staticRules[element.name] = existingRules;  
  128.                 if (argument.messages)  
  129.                     settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages );  
  130.                 break;  
  131.             case "remove":  
  132.                 if (!argument) {  
  133.                     delete staticRules[element.name];  
  134.                     return existingRules;  
  135.                 }  
  136.                 var filtered = {};  
  137.                 $.each(argument.split(/\s/), function(index, method) {  
  138.                     filtered[method] = existingRules[method];  
  139.                     delete existingRules[method];  
  140.                 });  
  141.                 return filtered;  
  142.             }  
  143.         }  
  144.           
  145.         var data = $.validator.normalizeRules(  
  146.         $.extend(  
  147.             {},  
  148.             $.validator.metadataRules(element),  
  149.             $.validator.classRules(element),  
  150.             $.validator.attributeRules(element),  
  151.             $.validator.staticRules(element)  
  152.         ), element);  
  153.           
  154.         // make sure required is at front  
  155.         if (data.required) {  
  156.             var param = data.required;  
  157.             delete data.required;  
  158.             data = $.extend({required: param}, data);  
  159.         }  
  160.           
  161.         return data;  
  162.     }  
  163. });  
  164.   
  165. // Custom selectors  
  166. $.extend($.expr[":"], {  
  167.     // http://docs.jquery.com/Plugins/Validation/blank  
  168.     blank: function(a) {return !$.trim("" + a.value);},  
  169.     // http://docs.jquery.com/Plugins/Validation/filled  
  170.     filled: function(a) {return !!$.trim("" + a.value);},  
  171.     // http://docs.jquery.com/Plugins/Validation/unchecked  
  172.     unchecked: function(a) {return !a.checked;}  
  173. });  
  174.   
  175. // constructor for validator  
  176. $.validator = function( options, form ) {  
  177.     this.settings = $.extend( true, {}, $.validator.defaults, options );  
  178.     this.currentForm = form;  
  179.     this.init();  
  180. };  
  181.   
  182. $.validator.format = function(source, params) {  
  183.     if ( arguments.length == 1 )   
  184.         return function() {  
  185.             var args = $.makeArray(arguments);  
  186.             args.unshift(source);  
  187.             return $.validator.format.apply( this, args );  
  188.         };  
  189.     if ( arguments.length > 2 && params.constructor != Array  ) {  
  190.         params = $.makeArray(arguments).slice(1);  
  191.     }  
  192.     if ( params.constructor != Array ) {  
  193.         params = [ params ];  
  194.     }  
  195.     $.each(params, function(i, n) {  
  196.         source = source.replace(new RegExp("\\{" + i + "\\}""g"), n);  
  197.     });  
  198.     return source;  
  199. };  
  200.   
  201. $.extend($.validator, {  
  202.       
  203.     defaults: {  
  204.         messages: {},  
  205.         groups: {},  
  206.         rules: {},  
  207.         errorClass: "error",  
  208.         validClass: "valid",  
  209.         errorElement: "label",  
  210.         focusInvalid: true,  
  211.         errorContainer: $( [] ),  
  212.         errorLabelContainer: $( [] ),  
  213.         onsubmit: true,  
  214.         ignore: [],  
  215.         ignoreTitle: false,  
  216.         onfocusin: function(element) {  
  217.             this.lastActive = element;  
  218.                   
  219.             // hide error label and remove error class on focus if enabled  
  220.             if ( this.settings.focusCleanup && !this.blockFocusCleanup ) {  
  221.                 this.settings.unhighlight && this.settings.unhighlight.call( this, element, this.settings.errorClass, this.settings.validClass );  
  222.                 this.errorsFor(element).hide();  
  223.             }  
  224.         },  
  225.         onfocusout: function(element) {  
  226.             if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) {  
  227.                 this.element(element);  
  228.             }  
  229.         },  
  230.         onkeyup: function(element) {  
  231.             if ( element.name in this.submitted || element == this.lastElement ) {  
  232.                 this.element(element);  
  233.             }  
  234.         },  
  235.         onclick: function(element) {  
  236.             // click on selects, radiobuttons and checkboxes  
  237.             if ( element.name in this.submitted )  
  238.                 this.element(element);  
  239.             // or option elements, check parent select in that case  
  240.             else if (element.parentNode.name in this.submitted)  
  241.                 this.element(element.parentNode);  
  242.         },  
  243.         highlight: function( element, errorClass, validClass ) {  
  244.             $(element).addClass(errorClass).removeClass(validClass);  
  245.         },  
  246.         unhighlight: function( element, errorClass, validClass ) {  
  247.             $(element).removeClass(errorClass).addClass(validClass);  
  248.         }  
  249.     },  
  250.   
  251.     // http://docs.jquery.com/Plugins/Validation/Validator/setDefaults  
  252.     setDefaults: function(settings) {  
  253.         $.extend( $.validator.defaults, settings );  
  254.     },  
  255.   
  256.     messages: {  
  257.         required: "不能为空.",  
  258.         remote: "Please fix this field.",  
  259.         email: "请输入正确的邮件地址.",  
  260.         url: "请输入正确的URL地址,如http://www.helloweba.com",  
  261.         date: "Please enter a valid date.",  
  262.         dateISO: "格式错误!",  
  263.         number: "请填写合适的数字.",  
  264.         digits: "只能输入数字.",  
  265.         creditcard: "Please enter a valid credit card number.",  
  266.         equalTo: "两次密码输入不一致.",  
  267.         accept: "文件格式不对!",  
  268.         maxlength: $.validator.format("您输入的字符数不能大于 {0} 位."),  
  269.         minlength: $.validator.format("您输入的字符数不能小于 {0} 位."),  
  270.         rangelength: $.validator.format("Please enter a value between {0} and {1} characters long."),  
  271.         range: $.validator.format("您输入的值的范围应该在 {0} 和 {1} 之间."),  
  272.         max: $.validator.format("Please enter a value less than or equal to {0}."),  
  273.         min: $.validator.format("Please enter a value greater than or equal to {0}.")  
  274.     },  
  275.       
  276.     autoCreateRanges: false,  
  277.       
  278.     prototype: {  
  279.           
  280.         init: function() {  
  281.             this.labelContainer = $(this.settings.errorLabelContainer);  
  282.             this.errorContext = this.labelContainer.length && this.labelContainer || $(this.currentForm);  
  283.             this.containers = $(this.settings.errorContainer).add( this.settings.errorLabelContainer );  
  284.             this.submitted = {};  
  285.             this.valueCache = {};  
  286.             this.pendingRequest = 0;  
  287.             this.pending = {};  
  288.             this.invalid = {};  
  289.             this.reset();  
  290.               
  291.             var groups = (this.groups = {});  
  292.             $.each(this.settings.groups, function(key, value) {  
  293.                 $.each(value.split(/\s/), function(index, name) {  
  294.                     groups[name] = key;  
  295.                 });  
  296.             });  
  297.             var rules = this.settings.rules;  
  298.             $.each(rules, function(key, value) {  
  299.                 rules[key] = $.validator.normalizeRule(value);  
  300.             });  
  301.               
  302.             function delegate(event) {  
  303.                 var validator = $.data(this[0].form, "validator"),  
  304.                     eventType = "on" + event.type.replace(/^validate/, "");  
  305.                 validator.settings[eventType] && validator.settings[eventType].call(validator, this[0] );  
  306.             }  
  307.             $(this.currentForm)  
  308.                 .validateDelegate(":text, :password, :file, select, textarea""focusin focusout keyup", delegate)  
  309.                 .validateDelegate(":radio, :checkbox, select, option""click", delegate);  
  310.   
  311.             if (this.settings.invalidHandler)  
  312.                 $(this.currentForm).bind("invalid-form.validate"this.settings.invalidHandler);  
  313.         },  
  314.   
  315.         // http://docs.jquery.com/Plugins/Validation/Validator/form  
  316.         form: function() {  
  317.             this.checkForm();  
  318.             $.extend(this.submitted, this.errorMap);  
  319.             this.invalid = $.extend({}, this.errorMap);  
  320.             if (!this.valid())  
  321.                 $(this.currentForm).triggerHandler("invalid-form", [this]);  
  322.             this.showErrors();  
  323.             return this.valid();  
  324.         },  
  325.           
  326.         checkForm: function() {  
  327.             this.prepareForm();  
  328.             for ( var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++ ) {  
  329.                 this.check( elements[i] );  
  330.             }  
  331.             return this.valid();   
  332.         },  
  333.           
  334.         // http://docs.jquery.com/Plugins/Validation/Validator/element  
  335.         element: function( element ) {  
  336.             element = this.clean( element );  
  337.             this.lastElement = element;  
  338.             this.prepareElement( element );  
  339.             this.currentElements = $(element);  
  340.             var result = this.check( element );  
  341.             if ( result ) {  
  342.                 delete this.invalid[element.name];  
  343.             } else {  
  344.                 this.invalid[element.name] = true;  
  345.             }  
  346.             if ( !this.numberOfInvalids() ) {  
  347.                 // Hide error containers on last error  
  348.                 this.toHide = this.toHide.add( this.containers );  
  349.             }  
  350.             this.showErrors();  
  351.             return result;  
  352.         },  
  353.   
  354.         // http://docs.jquery.com/Plugins/Validation/Validator/showErrors  
  355.         showErrors: function(errors) {  
  356.             if(errors) {  
  357.                 // add items to error list and map  
  358.                 $.extend( this.errorMap, errors );  
  359.                 this.errorList = [];  
  360.                 for ( var name in errors ) {  
  361.                     this.errorList.push({  
  362.                         message: errors[name],  
  363.                         element: this.findByName(name)[0]  
  364.                     });  
  365.                 }  
  366.                 // remove items from success list  
  367.                 this.successList = $.grep( this.successList, function(element) {  
  368.                     return !(element.name in errors);  
  369.                 });  
  370.             }  
  371.             this.settings.showErrors  
  372.                 ? this.settings.showErrors.call( thisthis.errorMap, this.errorList )  
  373.                 : this.defaultShowErrors();  
  374.         },  
  375.           
  376.         // http://docs.jquery.com/Plugins/Validation/Validator/resetForm  
  377.         resetForm: function() {  
  378.             if ( $.fn.resetForm )  
  379.                 $( this.currentForm ).resetForm();  
  380.             this.submitted = {};  
  381.             this.prepareForm();  
  382.             this.hideErrors();  
  383.             this.elements().removeClass( this.settings.errorClass );  
  384.         },  
  385.           
  386.         numberOfInvalids: function() {  
  387.             return this.objectLength(this.invalid);  
  388.         },  
  389.           
  390.         objectLength: function( obj ) {  
  391.             var count = 0;  
  392.             for ( var i in obj )  
  393.                 count++;  
  394.             return count;  
  395.         },  
  396.           
  397.         hideErrors: function() {  
  398.             this.addWrapper( this.toHide ).hide();  
  399.         },  
  400.           
  401.         valid: function() {  
  402.             return this.size() == 0;  
  403.         },  
  404.           
  405.         size: function() {  
  406.             return this.errorList.length;  
  407.         },  
  408.           
  409.         focusInvalid: function() {  
  410.             ifthis.settings.focusInvalid ) {  
  411.                 try {  
  412.                     $(this.findLastActive() || this.errorList.length && this.errorList[0].element || [])  
  413.                     .filter(":visible")  
  414.                     .focus()  
  415.                     // manually trigger focusin event; without it, focusin handler isn't called, findLastActive won't have anything to find  
  416.                     .trigger("focusin");  
  417.                 } catch(e) {  
  418.                     // ignore IE throwing errors when focusing hidden elements  
  419.                 }  
  420.             }  
  421.         },  
  422.           
  423.         findLastActive: function() {  
  424.             var lastActive = this.lastActive;  
  425.             return lastActive && $.grep(this.errorList, function(n) {  
  426.                 return n.element.name == lastActive.name;  
  427.             }).length == 1 && lastActive;  
  428.         },  
  429.           
  430.         elements: function() {  
  431.             var validator = this,  
  432.                 rulesCache = {};  
  433.               
  434.             // select all valid inputs inside the form (no submit or reset buttons)  
  435.             // workaround $Query([]).add until http://dev.jquery.com/ticket/2114 is solved  
  436.             return $([]).add(this.currentForm.elements)  
  437.             .filter(":input")  
  438.             .not(":submit, :reset, :image, [disabled]")  
  439.             .not( this.settings.ignore )  
  440.             .filter(function() {  
  441.                 !this.name && validator.settings.debug && window.console && console.error( "%o has no name assigned"this);  
  442.               
  443.                 // select only the first element for each name, and only those with rules specified  
  444.                 if ( this.name in rulesCache || !validator.objectLength($(this).rules()) )  
  445.                     return false;  
  446.                   
  447.                 rulesCache[this.name] = true;  
  448.                 return true;  
  449.             });  
  450.         },  
  451.           
  452.         clean: function( selector ) {  
  453.             return $( selector )[0];  
  454.         },  
  455.           
  456.         errors: function() {  
  457.             return $( this.settings.errorElement + "." + this.settings.errorClass, this.errorContext );  
  458.         },  
  459.           
  460.         reset: function() {  
  461.             this.successList = [];  
  462.             this.errorList = [];  
  463.             this.errorMap = {};  
  464.             this.toShow = $([]);  
  465.             this.toHide = $([]);  
  466.             this.currentElements = $([]);  
  467.         },  
  468.           
  469.         prepareForm: function() {  
  470.             this.reset();  
  471.             this.toHide = this.errors().add( this.containers );  
  472.         },  
  473.           
  474.         prepareElement: function( element ) {  
  475.             this.reset();  
  476.             this.toHide = this.errorsFor(element);  
  477.         },  
  478.       
  479.         check: function( element ) {  
  480.             element = this.clean( element );  
  481.               
  482.             // if radio/checkbox, validate first element in group instead  
  483.             if (this.checkable(element)) {  
  484.                 element = this.findByName( element.name )[0];  
  485.             }  
  486.               
  487.             var rules = $(element).rules();  
  488.             var dependencyMismatch = false;  
  489.             for( method in rules ) {  
  490.                 var rule = { method: method, parameters: rules[method] };  
  491.                 try {  
  492.                     var result = $.validator.methods[method].call( this, element.value.replace(/\r/g, ""), element, rule.parameters );  
  493.                       
  494.                     // if a method indicates that the field is optional and therefore valid,  
  495.                     // don't mark it as valid when there are no other rules  
  496.                     if ( result == "dependency-mismatch" ) {  
  497.                         dependencyMismatch = true;  
  498.                         continue;  
  499.                     }  
  500.                     dependencyMismatch = false;  
  501.                       
  502.                     if ( result == "pending" ) {  
  503.                         this.toHide = this.toHide.not( this.errorsFor(element) );  
  504.                         return;  
  505.                     }  
  506.                       
  507.                     if( !result ) {  
  508.                         this.formatAndAdd( element, rule );  
  509.                         return false;  
  510.                     }  
  511.                 } catch(e) {  
  512.                     this.settings.debug && window.console && console.log("exception occured when checking element " + element.id  
  513.                          + ", check the '" + rule.method + "' method", e);  
  514.                     throw e;  
  515.                 }  
  516.             }  
  517.             if (dependencyMismatch)  
  518.                 return;  
  519.             if ( this.objectLength(rules) )  
  520.                 this.successList.push(element);  
  521.             return true;  
  522.         },  
  523.           
  524.         // return the custom message for the given element and validation method  
  525.         // specified in the element's "messages" metadata  
  526.         customMetaMessage: function(element, method) {  
  527.             if (!$.metadata)  
  528.                 return;  
  529.               
  530.             var meta = this.settings.meta  
  531.                 ? $(element).metadata()[this.settings.meta]  
  532.                 : $(element).metadata();  
  533.               
  534.             return meta && meta.messages && meta.messages[method];  
  535.         },  
  536.           
  537.         // return the custom message for the given element name and validation method  
  538.         customMessage: function( name, method ) {  
  539.             var m = this.settings.messages[name];  
  540.             return m && (m.constructor == String  
  541.                 ? m  
  542.                 : m[method]);  
  543.         },  
  544.           
  545.         // return the first defined argument, allowing empty strings  
  546.         findDefined: function() {  
  547.             for(var i = 0; i < arguments.length; i++) {  
  548.                 if (arguments[i] !== undefined)  
  549.                     return arguments[i];  
  550.             }  
  551.             return undefined;  
  552.         },  
  553.           
  554.         defaultMessage: function( element, method) {  
  555.             return this.findDefined(  
  556.                 this.customMessage( element.name, method ),  
  557.                 this.customMetaMessage( element, method ),  
  558.                 // title is never undefined, so handle empty string as undefined  
  559.                 !this.settings.ignoreTitle && element.title || undefined,  
  560.                 $.validator.messages[method],  
  561.                 "<strong>Warning: No message defined for " + element.name + "</strong>"  
  562.             );  
  563.         },  
  564.           
  565.         formatAndAdd: function( element, rule ) {  
  566.             var message = this.defaultMessage( element, rule.method ),  
  567.                 theregex = /\$?\{(\d+)\}/g;  
  568.             if ( typeof message == "function" ) {  
  569.                 message = message.call(this, rule.parameters, element);  
  570.             } else if (theregex.test(message)) {  
  571.                 message = jQuery.format(message.replace(theregex, '{$1}'), rule.parameters);  
  572.             }             
  573.             this.errorList.push({  
  574.                 message: message,  
  575.                 element: element  
  576.             });  
  577.               
  578.             this.errorMap[element.name] = message;  
  579.             this.submitted[element.name] = message;  
  580.         },  
  581.           
  582.         addWrapper: function(toToggle) {  
  583.             if ( this.settings.wrapper )  
  584.                 toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) );  
  585.             return toToggle;  
  586.         },  
  587.           
  588.         defaultShowErrors: function() {  
  589.             for ( var i = 0; this.errorList[i]; i++ ) {  
  590.                 var error = this.errorList[i];  
  591.                 this.settings.highlight && this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass );  
  592.                 this.showLabel( error.element, error.message );  
  593.             }  
  594.             ifthis.errorList.length ) {  
  595.                 this.toShow = this.toShow.add( this.containers );  
  596.             }  
  597.             if (this.settings.success) {  
  598.                 for ( var i = 0; this.successList[i]; i++ ) {  
  599.                     this.showLabel( this.successList[i] );  
  600.                 }  
  601.             }  
  602.             if (this.settings.unhighlight) {  
  603.                 for ( var i = 0, elements = this.validElements(); elements[i]; i++ ) {  
  604.                     this.settings.unhighlight.call( this, elements[i], this.settings.errorClass, this.settings.validClass );  
  605.                 }  
  606.             }  
  607.             this.toHide = this.toHide.not( this.toShow );  
  608.             this.hideErrors();  
  609.             this.addWrapper( this.toShow ).show();  
  610.         },  
  611.           
  612.         validElements: function() {  
  613.             return this.currentElements.not(this.invalidElements());  
  614.         },  
  615.           
  616.         invalidElements: function() {  
  617.             return $(this.errorList).map(function() {  
  618.                 return this.element;  
  619.             });  
  620.         },  
  621.           
  622.         showLabel: function(element, message) {  
  623.             var label = this.errorsFor( element );  
  624.             if ( label.length ) {  
  625.                 // refresh error/success class  
  626.                 label.removeClass().addClass( this.settings.errorClass );  
  627.               
  628.                 // check if we have a generated label, replace the message then  
  629.                 label.attr("generated") && label.html(message);  
  630.             } else {  
  631.                 // create label  
  632.                 label = $("<" + this.settings.errorElement + "/>")  
  633.                     .attr({"for":  this.idOrName(element), generated: true})  
  634.                     .addClass(this.settings.errorClass)  
  635.                     .html(message || "");  
  636.                 if ( this.settings.wrapper ) {  
  637.                     // make sure the element is visible, even in IE  
  638.                     // actually showing the wrapped element is handled elsewhere  
  639.                     label = label.hide().show().wrap("<" + this.settings.wrapper + "/>").parent();  
  640.                 }  
  641.                 if ( !this.labelContainer.append(label).length )  
  642.                     this.settings.errorPlacement  
  643.                         ? this.settings.errorPlacement(label, $(element) )  
  644.                         : label.insertAfter(element);  
  645.             }  
  646.             if ( !message && this.settings.success ) {  
  647.                 label.text("");  
  648.                 typeof this.settings.success == "string"  
  649.                     ? label.addClass( this.settings.success )  
  650.                     : this.settings.success( label );  
  651.             }  
  652.             this.toShow = this.toShow.add(label);  
  653.         },  
  654.           
  655.         errorsFor: function(element) {  
  656.             var name = this.idOrName(element);  
  657.             return this.errors().filter(function() {  
  658.                 return $(this).attr('for') == name;  
  659.             });  
  660.         },  
  661.           
  662.         idOrName: function(element) {  
  663.             return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name);  
  664.         },  
  665.   
  666.         checkable: function( element ) {  
  667.             return /radio|checkbox/i.test(element.type);  
  668.         },  
  669.           
  670.         findByName: function( name ) {  
  671.             // select by name and filter by form for performance over form.find("[name=...]")  
  672.             var form = this.currentForm;  
  673.             return $(document.getElementsByName(name)).map(function(index, element) {  
  674.                 return element.form == form && element.name == name && element  || null;  
  675.             });  
  676.         },  
  677.           
  678.         getLength: function(value, element) {  
  679.             switch( element.nodeName.toLowerCase() ) {  
  680.             case 'select':  
  681.                 return $("option:selected", element).length;  
  682.             case 'input':  
  683.                 ifthis.checkable( element) )  
  684.                     return this.findByName(element.name).filter(':checked').length;  
  685.             }  
  686.             return value.length;  
  687.         },  
  688.       
  689.         depend: function(param, element) {  
  690.             return this.dependTypes[typeof param]  
  691.                 ? this.dependTypes[typeof param](param, element)  
  692.                 : true;  
  693.         },  
  694.       
  695.         dependTypes: {  
  696.             "boolean"function(param, element) {  
  697.                 return param;  
  698.             },  
  699.             "string"function(param, element) {  
  700.                 return !!$(param, element.form).length;  
  701.             },  
  702.             "function"function(param, element) {  
  703.                 return param(element);  
  704.             }  
  705.         },  
  706.           
  707.         optional: function(element) {  
  708.             return !$.validator.methods.required.call(this, $.trim(element.value), element) && "dependency-mismatch";  
  709.         },  
  710.           
  711.         startRequest: function(element) {  
  712.             if (!this.pending[element.name]) {  
  713.                 this.pendingRequest++;  
  714.                 this.pending[element.name] = true;  
  715.             }  
  716.         },  
  717.           
  718.         stopRequest: function(element, valid) {  
  719.             this.pendingRequest--;  
  720.             // sometimes synchronization fails, make sure pendingRequest is never < 0  
  721.             if (this.pendingRequest < 0)  
  722.                 this.pendingRequest = 0;  
  723.             delete this.pending[element.name];  
  724.             if ( valid && this.pendingRequest == 0 && this.formSubmitted && this.form() ) {  
  725.                 $(this.currentForm).submit();  
  726.                 this.formSubmitted = false;  
  727.             } else if (!valid && this.pendingRequest == 0 && this.formSubmitted) {  
  728.                 $(this.currentForm).triggerHandler("invalid-form", [this]);  
  729.                 this.formSubmitted = false;  
  730.             }  
  731.         },  
  732.           
  733.         previousValue: function(element) {  
  734.             return $.data(element, "previousValue") || $.data(element, "previousValue", {  
  735.                 old: null,  
  736.                 valid: true,  
  737.                 message: this.defaultMessage( element, "remote" )  
  738.             });  
  739.         }  
  740.           
  741.     },  
  742.       
  743.     classRuleSettings: {  
  744.         required: {required: true},  
  745.         email: {email: true},  
  746.         url: {url: true},  
  747.         date: {date: true},  
  748.         dateISO: {dateISO: true},  
  749.         dateDE: {dateDE: true},  
  750.         number: {number: true},  
  751.         numberDE: {numberDE: true},  
  752.         digits: {digits: true},  
  753.         creditcard: {creditcard: true}  
  754.     },  
  755.       
  756.     addClassRules: function(className, rules) {  
  757.         className.constructor == String ?  
  758.             this.classRuleSettings[className] = rules :  
  759.             $.extend(this.classRuleSettings, className);  
  760.     },  
  761.       
  762.     classRules: function(element) {  
  763.         var rules = {};  
  764.         var classes = $(element).attr('class');  
  765.         classes && $.each(classes.split(' '), function() {  
  766.             if (this in $.validator.classRuleSettings) {  
  767.                 $.extend(rules, $.validator.classRuleSettings[this]);  
  768.             }  
  769.         });  
  770.         return rules;  
  771.     },  
  772.       
  773.     attributeRules: function(element) {  
  774.         var rules = {};  
  775.         var $element = $(element);  
  776.           
  777.         for (method in $.validator.methods) {  
  778.             var value = $element.attr(method);  
  779.             if (value) {  
  780.                 rules[method] = value;  
  781.             }  
  782.         }  
  783.           
  784.         // maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs  
  785.         if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) {  
  786.             delete rules.maxlength;  
  787.         }  
  788.           
  789.         return rules;  
  790.     },  
  791.       
  792.     metadataRules: function(element) {  
  793.         if (!$.metadata) return {};  
  794.           
  795.         var meta = $.data(element.form, 'validator').settings.meta;  
  796.         return meta ?  
  797.             $(element).metadata()[meta] :  
  798.             $(element).metadata();  
  799.     },  
  800.       
  801.     staticRules: function(element) {  
  802.         var rules = {};  
  803.         var validator = $.data(element.form, 'validator');  
  804.         if (validator.settings.rules) {  
  805.             rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {};  
  806.         }  
  807.         return rules;  
  808.     },  
  809.       
  810.     normalizeRules: function(rules, element) {  
  811.         // handle dependency check  
  812.         $.each(rules, function(prop, val) {  
  813.             // ignore rule when param is explicitly false, eg. required:false  
  814.             if (val === false) {  
  815.                 delete rules[prop];  
  816.                 return;  
  817.             }  
  818.             if (val.param || val.depends) {  
  819.                 var keepRule = true;  
  820.                 switch (typeof val.depends) {  
  821.                     case "string":  
  822.                         keepRule = !!$(val.depends, element.form).length;  
  823.                         break;  
  824.                     case "function":  
  825.                         keepRule = val.depends.call(element, element);  
  826.                         break;  
  827.                 }  
  828.                 if (keepRule) {  
  829.                     rules[prop] = val.param !== undefined ? val.param : true;  
  830.                 } else {  
  831.                     delete rules[prop];  
  832.                 }  
  833.             }  
  834.         });  
  835.           
  836.         // evaluate parameters  
  837.         $.each(rules, function(rule, parameter) {  
  838.             rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter;  
  839.         });  
  840.           
  841.         // clean number parameters  
  842.         $.each(['minlength''maxlength''min''max'], function() {  
  843.             if (rules[this]) {  
  844.                 rules[this] = Number(rules[this]);  
  845.             }  
  846.         });  
  847.         $.each(['rangelength''range'], function() {  
  848.             if (rules[this]) {  
  849.                 rules[this] = [Number(rules[this][0]), Number(rules[this][1])];  
  850.             }  
  851.         });  
  852.           
  853.         if ($.validator.autoCreateRanges) {  
  854.             // auto-create ranges  
  855.             if (rules.min && rules.max) {  
  856.                 rules.range = [rules.min, rules.max];  
  857.                 delete rules.min;  
  858.                 delete rules.max;  
  859.             }  
  860.             if (rules.minlength && rules.maxlength) {  
  861.                 rules.rangelength = [rules.minlength, rules.maxlength];  
  862.                 delete rules.minlength;  
  863.                 delete rules.maxlength;  
  864.             }  
  865.         }  
  866.           
  867.         // To support custom messages in metadata ignore rule methods titled "messages"  
  868.         if (rules.messages) {  
  869.             delete rules.messages;  
  870.         }  
  871.           
  872.         return rules;  
  873.     },  
  874.       
  875.     // Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}  
  876.     normalizeRule: function(data) {  
  877.         iftypeof data == "string" ) {  
  878.             var transformed = {};  
  879.             $.each(data.split(/\s/), function() {  
  880.                 transformed[this] = true;  
  881.             });  
  882.             data = transformed;  
  883.         }  
  884.         return data;  
  885.     },  
  886.       
  887.     // http://docs.jquery.com/Plugins/Validation/Validator/addMethod  
  888.     addMethod: function(name, method, message) {  
  889.         $.validator.methods[name] = method;  
  890.         $.validator.messages[name] = message != undefined ? message : $.validator.messages[name];  
  891.         if (method.length < 3) {  
  892.             $.validator.addClassRules(name, $.validator.normalizeRule(name));  
  893.         }  
  894.     },  
  895.   
  896.     methods: {  
  897.   
  898.         // http://docs.jquery.com/Plugins/Validation/Methods/required  
  899.         required: function(value, element, param) {  
  900.             // check if dependency is met  
  901.             if ( !this.depend(param, element) )  
  902.                 return "dependency-mismatch";  
  903.             switch( element.nodeName.toLowerCase() ) {  
  904.             case 'select':  
  905.                 // could be an array for select-multiple or a string, both are fine this way  
  906.                 var val = $(element).val();  
  907.                 return val && val.length > 0;  
  908.             case 'input':  
  909.                 if ( this.checkable(element) )  
  910.                     return this.getLength(value, element) > 0;  
  911.             default:  
  912.                 return $.trim(value).length > 0;  
  913.             }  
  914.         },  
  915.           
  916.         // http://docs.jquery.com/Plugins/Validation/Methods/remote  
  917.         remote: function(value, element, param) {  
  918.             if ( this.optional(element) )  
  919.                 return "dependency-mismatch";  
  920.               
  921.             var previous = this.previousValue(element);  
  922.             if (!this.settings.messages[element.name] )  
  923.                 this.settings.messages[element.name] = {};  
  924.             previous.originalMessage = this.settings.messages[element.name].remote;  
  925.             this.settings.messages[element.name].remote = previous.message;  
  926.               
  927.             param = typeof param == "string" && {url:param} || param;   
  928.               
  929.             if ( previous.old !== value ) {  
  930.                 previous.old = value;  
  931.                 var validator = this;  
  932.                 this.startRequest(element);  
  933.                 var data = {};  
  934.                 data[element.name] = value;  
  935.                 $.ajax($.extend(true, {  
  936.                     url: param,  
  937.                     //url: param.url,  
  938.                     mode: "abort",  
  939.                     port: "validate" + element.name,  
  940.                     dataType: "json",  
  941.                     data: data,  
  942.                     //data: param.data || data,  
  943.                     success: function(response) {  
  944.                         validator.settings.messages[element.name].remote = previous.originalMessage;  
  945.                         var valid = response === true;  
  946.                         if ( valid ) {  
  947.                             var submitted = validator.formSubmitted;  
  948.                             validator.prepareElement(element);  
  949.                             validator.formSubmitted = submitted;  
  950.                             validator.successList.push(element);  
  951.                             validator.showErrors();  
  952.                         } else {  
  953.                             var errors = {};  
  954.                             var message = (previous.message = response || validator.defaultMessage( element, "remote" ));  
  955.                             errors[element.name] = $.isFunction(message) ? message(value) : message;  
  956.                             validator.showErrors(errors);  
  957.                         }  
  958.                         previous.valid = valid;  
  959.                         validator.stopRequest(element, valid);  
  960.                     }  
  961.                 }, param));  
  962.                 return "pending";  
  963.             } else ifthis.pending[element.name] ) {  
  964.                 return "pending";  
  965.             }  
  966.             return previous.valid;  
  967.         },  
  968.   
  969.         // http://docs.jquery.com/Plugins/Validation/Methods/minlength  
  970.         minlength: function(value, element, param) {  
  971.             return this.optional(element) || this.getLength($.trim(value), element) >= param;  
  972.         },  
  973.           
  974.         // http://docs.jquery.com/Plugins/Validation/Methods/maxlength  
  975.         maxlength: function(value, element, param) {  
  976.             return this.optional(element) || this.getLength($.trim(value), element) <= param;  
  977.         },  
  978.           
  979.         // http://docs.jquery.com/Plugins/Validation/Methods/rangelength  
  980.         rangelength: function(value, element, param) {  
  981.             var length = this.getLength($.trim(value), element);  
  982.             return this.optional(element) || ( length >= param[0] && length <= param[1] );  
  983.         },  
  984.           
  985.         // http://docs.jquery.com/Plugins/Validation/Methods/min  
  986.         min: function( value, element, param ) {  
  987.             return this.optional(element) || value >= param;  
  988.         },  
  989.           
  990.         // http://docs.jquery.com/Plugins/Validation/Methods/max  
  991.         max: function( value, element, param ) {  
  992.             return this.optional(element) || value <= param;  
  993.         },  
  994.           
  995.         // http://docs.jquery.com/Plugins/Validation/Methods/range  
  996.         range: function( value, element, param ) {  
  997.             return this.optional(element) || ( value >= param[0] && value <= param[1] );  
  998.         },  
  999.           
  1000.         // http://docs.jquery.com/Plugins/Validation/Methods/email  
  1001.         email: function(value, element) {  
  1002.             // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/  
  1003.             return this.optional(element) || /^((([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(value);  
  1004.         },  
  1005.           
  1006.         // 验证身份证  
  1007.         //dateISO: function(value, element) {  
  1008.         //  return this.optional(element) || /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(value);  
  1009.         //},  
  1010.           
  1011.         // http://docs.jquery.com/Plugins/Validation/Methods/url  
  1012.         url: function(value, element) {  
  1013.             // contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/  
  1014.             return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&' \*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([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])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&' \*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&' \*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&' \*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&' \*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);  
  1015.         },  
  1016.           
  1017.         // http://docs.jquery.com/Plugins/Validation/Methods/date  
  1018.         date: function(value, element) {  
  1019.             return this.optional(element) || !/Invalid|NaN/.test(new Date(value));  
  1020.         },  
  1021.       
  1022.         // http://docs.jquery.com/Plugins/Validation/Methods/dateISO  
  1023.         dateISO: function(value, element) {  
  1024.             return this.optional(element) || /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(value);  
  1025.         },  
  1026.       
  1027.         // http://docs.jquery.com/Plugins/Validation/Methods/number  
  1028.         number: function(value, element) {  
  1029.             return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value);  
  1030.         },  
  1031.       
  1032.         // http://docs.jquery.com/Plugins/Validation/Methods/digits  
  1033.         digits: function(value, element) {  
  1034.             return this.optional(element) || /^\d+$/.test(value);  
  1035.         },  
  1036.           
  1037.         // http://docs.jquery.com/Plugins/Validation/Methods/creditcard  
  1038.         // based on http://en.wikipedia.org/wiki/Luhn  
  1039.         creditcard: function(value, element) {  
  1040.             if ( this.optional(element) )  
  1041.                 return "dependency-mismatch";  
  1042.             // accept only digits and dashes  
  1043.             if (/[^0-9-]+/.test(value))  
  1044.                 return false;  
  1045.             var nCheck = 0,  
  1046.                 nDigit = 0,  
  1047.                 bEven = false;  
  1048.   
  1049.             value = value.replace(/\D/g, "");  
  1050.   
  1051.             for (var n = value.length - 1; n >= 0; n--) {  
  1052.                 var cDigit = value.charAt(n);  
  1053.                 var nDigit = parseInt(cDigit, 10);  
  1054.                 if (bEven) {  
  1055.                     if ((nDigit *= 2) > 9)  
  1056.                         nDigit -= 9;  
  1057.                 }  
  1058.                 nCheck += nDigit;  
  1059.                 bEven = !bEven;  
  1060.             }  
  1061.   
  1062.             return (nCheck % 10) == 0;  
  1063.         },  
  1064.           
  1065.         // http://docs.jquery.com/Plugins/Validation/Methods/accept  
  1066.         accept: function(value, element, param) {  
  1067.             param = typeof param == "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif";  
  1068.             return this.optional(element) || value.match(new RegExp(".(" + param + ")$""i"));   
  1069.         },  
  1070.           
  1071.         // http://docs.jquery.com/Plugins/Validation/Methods/equalTo  
  1072.         equalTo: function(value, element, param) {  
  1073.             // bind to the blur event of the target in order to revalidate whenever the target field is updated  
  1074.             // TODO find a way to bind the event just once, avoiding the unbind-rebind overhead  
  1075.             var target = $(param).unbind(".validate-equalTo").bind("blur.validate-equalTo"function() {  
  1076.                 $(element).valid();  
  1077.             });  
  1078.             return value == target.val();  
  1079.         }  
  1080.           
  1081.     }  
  1082.       
  1083. });  
  1084.   
  1085. // deprecated, use $.validator.format instead  
  1086. $.format = $.validator.format;  
  1087.   
  1088. })(jQuery);  
  1089.   
  1090. // ajax mode: abort  
  1091. // usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});  
  1092. // if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()   
  1093. ;(function($) {  
  1094.     var ajax = $.ajax;  
  1095.     var pendingRequests = {};  
  1096.     $.ajax = function(settings) {  
  1097.         // create settings for compatibility with ajaxSetup  
  1098.         settings = $.extend(settings, $.extend({}, $.ajaxSettings, settings));  
  1099.         var port = settings.port;  
  1100.         if (settings.mode == "abort") {  
  1101.             if ( pendingRequests[port] ) {  
  1102.                 pendingRequests[port].abort();  
  1103.             }  
  1104.             return (pendingRequests[port] = ajax.apply(this, arguments));  
  1105.         }  
  1106.         return ajax.apply(this, arguments);  
  1107.     };  
  1108. })(jQuery);  
  1109.   
  1110. // provides cross-browser focusin and focusout events  
  1111. // IE has native support, in other browsers, use event caputuring (neither bubbles)  
  1112.   
  1113. // provides delegate(type: String, delegate: Selector, handler: Callback) plugin for easier event delegation  
  1114. // handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target   
  1115. ;(function($) {  
  1116.     // only implement if not provided by jQuery core (since 1.4)  
  1117.     // TODO verify if jQuery 1.4's implementation is compatible with older jQuery special-event APIs  
  1118.     if (!jQuery.event.special.focusin && !jQuery.event.special.focusout && document.addEventListener) {  
  1119.         $.each({  
  1120.             focus: 'focusin',  
  1121.             blur: 'focusout'      
  1122.         }, function( original, fix ){  
  1123.             $.event.special[fix] = {  
  1124.                 setup:function() {  
  1125.                     this.addEventListener( original, handler, true );  
  1126.                 },  
  1127.                 teardown:function() {  
  1128.                     this.removeEventListener( original, handler, true );  
  1129.                 },  
  1130.                 handler: function(e) {  
  1131.                     arguments[0] = $.event.fix(e);  
  1132.                     arguments[0].type = fix;  
  1133.                     return $.event.handle.apply(this, arguments);  
  1134.                 }  
  1135.             };  
  1136.             function handler(e) {  
  1137.                 e = $.event.fix(e);  
  1138.                 e.type = fix;  
  1139.                 return $.event.handle.call(this, e);  
  1140.             }  
  1141.         });  
  1142.     };  
  1143.     $.extend($.fn, {  
  1144.         validateDelegate: function(delegate, type, handler) {  
  1145.             return this.bind(type, function(event) {  
  1146.                 var target = $(event.target);  
  1147.                 if (target.is(delegate)) {  
  1148.                     return handler.apply(target, arguments);  
  1149.                 }  
  1150.             });  
  1151.         }  
  1152.     });  
  1153. })(jQuery); 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值