jquery各种验证

首选需要引入3个js文件jquery.validationEngine.js     validation.js   validationEngine-zh_CN.js


validationEngine-zh_CN.js

(function($){
    $.fn.validationEngineLanguage = function(){
    };
    $.validationEngineLanguage = {
        newLang: function(){
            $.validationEngineLanguage.allRules = {
                "required": { // Add your regex rules here, you can take telephone as an example
                    "regex": "none",
                    "alertText": "* 此处不可空白",
                    "alertTextCheckboxMultiple": "* 请选择",
                    "alertTextCheckboxe": "* 您必须钩选此栏",
                    "alertTextDateRange": "* 日期范围不可空白"
                },
                "dateRange": {
                    "regex": "none",
                    "alertText": "* 无效的 ",
                    "alertText2": " 日期范围"
                },
                "dateTimeRange": {
                    "regex": "none",
                    "alertText": "* 无效的 ",
                    "alertText2": " 时间范围"
                },
                "minSize": {
                    "regex": "none",
                    "alertText": "* 最少 ",
                    "alertText2": " 个字符"
                },
                "maxSize": {
                    "regex": "none",
                    "alertText": "* 最多 ",
                    "alertText2": " 个字符"
                },
				"groupRequired": {
                    "regex": "none",
                    "alertText": "* 你必需选填其中一个栏位"
                },
                "min": {
                    "regex": "none",
                    "alertText": "* 最小值為 "
                },
                "max": {
                    "regex": "none",
                    "alertText": "* 最大值为 "
                },
                "past": {
                    "regex": "none",
                    "alertText": "* 日期必需早于 "
                },
                "future": {
                    "regex": "none",
                    "alertText": "* 日期必需晚于 "
                },	
                "maxCheckbox": {
                    "regex": "none",
                    "alertText": "* 最多选取 ",
                    "alertText2": " 个项目"
                },
                "minCheckbox": {
                    "regex": "none",
                    "alertText": "* 请选择 ",
                    "alertText2": " 个项目"
                },
                "equals": {
                    "regex": "none",
                    "alertText": "* 请输入与上面相同的密码"
                },
                "creditCard": {
                    "regex": "/^\d{5}$/g",
                    "alertText": "* 无效的信用卡号码"
                },
                "phone": {
                    // credit: jquery.h5validate.js / orefalo
                    "regex": /^([\+][0-9]{1,3}[ \.\-])?([\(]{1}[0-9]{2,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/,
                    "alertText": "* 无效的电话号码"
                },
                "email": {
                    // Shamelessly lifted from Scott Gonzalez via the Bassistance Validation plugin http://projects.scottsplayground.com/email_address_validation/
                    "regex": /^((([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,
                    "alertText": "* 邮件地址无效"
                },
                "integer": {
                    "regex": /^[\-\+]?\d+$/,
                    "alertText": "* 不是有效的整数"
                },
                "number": {
                    // Number, including positive, negative, and floating decimal. credit: orefalo
                    "regex": /^[\-\+]?(([0-9]+)([\.,]([0-9]+))?|([\.,]([0-9]+))?)$/,
                    "alertText": "* 无效的数字"
                },
                "date": {
                    "regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/,
                    "alertText": "* 无效的日期,格式必需为 YYYY-MM-DD"
                },
                "ipv4": {
                    "regex": /^((([01]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))[.]){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))$/,
                    "alertText": "* 无效的 IP 地址"
                },
                "url": {
                    "regex": /^(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,
                    "alertText": "* Invalid URL"
                },
                "onlyNumberSp": {
                    "regex": /^[0-9\ ]+$/,
                    "alertText": "* 只能填数字"
                },
                "onlyLetterSp": {
                    "regex": /^[a-zA-Z\ \']+$/,
                    "alertText": "* 只接受英文字母大小写"
                },
                "onlyLetterNumber": {
                    "regex": /^[0-9a-zA-Z]+$/,
                    "alertText": "* 不接受特殊字符"
                },
                // --- CUSTOM RULES -- Those are specific to the demos, they can be removed or changed to your likings
                "ajaxUserCall": {
                    "url": "ajaxValidateFieldUser",
                    // you may want to pass extra data on the ajax call
                    "extraData": "name=eric",
                    "alertText": "* 此名称已被其他人使用",
                    "alertTextLoad": "* 正在确认名称是否有其他人使用,请稍等。"
                },
				"ajaxUserCallPhp": {
                    "url": "phpajax/ajaxValidateFieldUser.php",
                    // you may want to pass extra data on the ajax call
                    "extraData": "name=eric",
                    // if you provide an "alertTextOk", it will show as a green prompt when the field validates
                    "alertTextOk": "* 此帐号名称可以使用",
                    "alertText": "* 此名称已被其他人使用",
                    "alertTextLoad": "* 正在确认帐号名称是否有其他人使用,请稍等。"
                },
                "ajaxNameCall": {
                    // remote json service location
                    "url": "ajaxValidateFieldName",
                    // error
                    "alertText": "* 此名称可以使用",
                    // if you provide an "alertTextOk", it will show as a green prompt when the field validates
                    "alertTextOk": "* 此名称已被其他人使用",
                    // speaks by itself
                    "alertTextLoad": "* 正在确认名称是否有其他人使用,请稍等。"
                },
				 "ajaxNameCallPhp": {
	                    // remote json service location
	                    "url": "phpajax/ajaxValidateFieldName.php",
	                    // error
	                    "alertText": "* 此名称已被其他人使用",
	                    // speaks by itself
	                    "alertTextLoad": "* 正在确认名称是否有其他人使用,请稍等。"
	                },
                "validate2fields": {
                    "alertText": "* 请输入 HELLO"
                },
	            //tls warning:homegrown not fielded 
                "dateFormat":{
                    "regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:0?[1-9]|1[0-2])(\/|-)(?:0?[1-9]|1\d|2[0-8]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(0?2(\/|-)29)(\/|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$/,
                    "alertText": "* 无效的日期格式"
                },
                //tls warning:homegrown not fielded 
				"dateTimeFormat": {
	                "regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|AM|PM){1}$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^((1[012]|0?[1-9]){1}\/(0?[1-9]|[12][0-9]|3[01]){1}\/\d{2,4}\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|AM|PM){1})$/,
                    "alertText": "* 无效的日期或时间格式",
                    "alertText2": "可接受的格式: ",
                    "alertText3": "mm/dd/yyyy hh:mm:ss AM|PM 或 ", 
                    "alertText4": "yyyy-mm-dd hh:mm:ss AM|PM"
	            },
	            "QQ": {
                    "regex": /^\d{5,11}$/,
                    "alertText": "* QQ必须是数字且长度应在5-11位之间"
                },
	            //金额输入限制
	            "onlyNum": {		
					"regex": /^(\d+\.\d{1,2}|\d+)$/,
					"alertText": "* 只能输入数字及后2位小数"				
				},
				//地址栏值为0重新选择
	            "selectAddr": {		
					"regex": /^[0-9]*[1-9][0-9]*$/,
					"alertText": "* 请选择地址"				
				},
				//数字必须大于0
	            "gtZero": {		
					"regex": /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/,
					"alertText": "* 必须大于0"				
				},
				//操作员密码为6-32位数字
	            "operatorPSW": {		
					"regex": /^\d{6,32}$/,
					"alertText": "* 密码必须为6-32位数字"				
				},
				//商户编号为16位字符
	            "shopNum": {		
					"regex": /^\w{15}?$/,
					"alertText": "* 商户编号为15位字符"				
				},
				//11位手机号
	            "cellPhone": {		
					"regex": /^([0-9]{11})?$/,
					"alertText": "* 只能输入11位手机号"				
				}, //11位手机号
	            "idCard": {		
					"regex": /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/,
					"alertText": "* 请输入正确的身份证号"				
				},"loginPwd": {
	                "regex": /^(\w){6,32}$/,
	                "alertText": "* 密码长度在6之32位之间"
	            },"post": {
	                "regex": /^[1-9]{1}[0-9]{5}$/,
	                "alertText": "* 请输入正确的邮编"
	            },"card": {
	                "regex": /^\d{16}$|^\d{19}$|^\d{6}[- ]\d{10,13}$|^\d{4}[- ]\d{4}[- ]\d{4}[- ]\d{4,7}$/,
	                "alertText": "* 无效的银行卡号码"
	            },
	            //银行卡号
                "bankCardAccount": {
                	"regex": /^[0-9]{16,19}$/,
                	"alertText": "* 无效的银行卡号"
                }
            };          
        }
    };
    $.validationEngineLanguage.newLang();
})(jQuery);


validation.js


$(function() {
	$("#formID").validationEngine();
	$("#formId").validationEngine();
});


jquery.validationEngine.js
/* * Inline Form Validation Engine 2.5.1, jQuery plugin * * Copyright(c) 2010, Cedric Dugas * http://www.position-absolute.com * * 2.0 Rewrite by Olivier Refalo * http://www.crionics.com * * Form validation engine allowing custom regex rules to be added. * Licensed under the MIT License */ (function($) { "use strict"; var methods = { /** * Kind of the constructor, called before any action * @param {Map} user options */ init: function(options) { var form = this; if (!form.data('jqv') || form.data('jqv') == null ) { options = methods._saveOptions(form, options); // bind all formError elements to close on click $(".formError").live("click", function() { $(this).fadeOut(150, function() { // remove prompt once invisible $(this).parent('.formErrorOuter').remove(); $(this).remove(); }); }); } return this; },/*** Attachs jQuery.validationEngine to form.submit and field.blur events* Takes an optional params: a list of options* ie. jQuery("#formID1").validationEngine('attach', {promptPosition : "centerRight"});*/attach: function(userOptions) {var form = this;var options;if(userOptions)options = methods._saveOptions(form, userOptions);elseoptions = form.data('jqv');options.validateAttribute = (form.find("[data-validation-engine*=validate]").length) ? "data-validation-engine" : "class";if (options.binded) {// bind fieldsform.find("["+options.validateAttribute+"*=validate]").not("[type=checkbox]").not("[type=radio]").not(".datepicker").bind(options.validationEventTrigger, methods._onFieldEvent);form.find("["+options.validateAttribute+"*=validate][type=checkbox],["+options.validateAttribute+"*=validate][type=radio]").bind("click", methods._onFieldEvent);form.find("["+options.validateAttribute+"*=validate][class*=datepicker]").bind(options.validationEventTrigger,{"delay": 300}, methods._onFieldEvent);}if (options.autoPositionUpdate) {$(window).bind("resize", {"noAnimation": true,"formElem": form}, methods.updatePromptsPosition);}// bind form.submitform.bind("submit", methods._onSubmitEvent);return this;},/*** Unregisters any bindings that may point to jQuery.validaitonEngine*/detach: function() {var form = this;var options = form.data('jqv');// unbind fieldsform.find("["+options.validateAttribute+"*=validate]").not("[type=checkbox]").unbind(options.validationEventTrigger, methods._onFieldEvent);form.find("["+options.validateAttribute+"*=validate][type=checkbox],[class*=validate][type=radio]").unbind("click", methods._onFieldEvent);// unbind form.submitform.unbind("submit", methods.onAjaxFormComplete);// unbind live fields (kill)form.find("["+options.validateAttribute+"*=validate]").not("[type=checkbox]").die(options.validationEventTrigger, methods._onFieldEvent);form.find("["+options.validateAttribute+"*=validate][type=checkbox]").die("click", methods._onFieldEvent);// unbind form.submitform.die("submit", methods.onAjaxFormComplete);form.removeData('jqv');if (options.autoPositionUpdate) {$(window).unbind("resize", methods.updatePromptsPosition)}return this;},/*** Validates the form fields, shows prompts accordingly.* Note: There is no ajax form validation with this method, only field ajax validation are evaluated** @return true if the form validates, false if it fails*/ validate: function() { return methods._validateFields(this); }, /** * Validates one field, shows prompt accordingly. * Note: There is no ajax form validation with this method, only field ajax validation are evaluated * * @return true if the form validates, false if it fails */ validateField: function(el) { var options = $(this).data('jqv'); var r = methods._validateField($(el), options); if (options.onSuccess && options.InvalidFields.length == 0) options.onSuccess(); else if (options.onFailure && options.InvalidFields.length > 0) options.onFailure(); return r; }, /** * Validates the form fields, shows prompts accordingly. * Note: this methods performs fields and form ajax validations(if setup) * * @return true if the form validates, false if it fails, undefined if ajax is used for form validation */ validateform: function() { return methods._onSubmitEvent.call(this); },/*** Redraw prompts position, useful when you change the DOM state when validating*/updatePromptsPosition: function(event) {if (event && this == window) {var form = event.data.formElem;var noAnimation = event.data.noAnimation;}elsevar form = $(this.closest('form'));var options = form.data('jqv');// No option, take default oneform.find('['+options.validateAttribute+'*=validate]').not(':hidden').not(":disabled").each(function(){var field = $(this);var prompt = methods._getPrompt(field);var promptText = $(prompt).find(".formErrorContent").html();if(prompt)methods._updatePrompt(field, $(prompt), promptText, undefined, false, options, noAnimation);});return this;},/*** Displays a prompt on a element.* Note that the element needs an id!** @param {String} promptText html text to display type* @param {String} type the type of bubble: 'pass' (green), 'load' (black) anything else (red)* @param {String} possible values topLeft, topRight, bottomLeft, centerRight, bottomRight*/showPrompt: function(promptText, type, promptPosition, showArrow) {var form = this.closest('form');var options = form.data('jqv');// No option, take default oneif(!options) options = methods._saveOptions(this, options);if(promptPosition)options.promptPosition=promptPosition;options.showArrow = showArrow==true;methods._showPrompt(this, promptText, type, false, options);return this;},/*** Closes all error prompts on the page*/hidePrompt: function() {var form = this;var options = form.data('jqv');var promptClass = "."+ methods._getClassName($(this).attr("id")) + "formError";$(promptClass).fadeTo(options.fadeDuration, 0.3, function() {$(this).parent('.formErrorOuter').remove();$(this).remove();});return this;},/*** Closes form error prompts, CAN be invidual*/ hide: function() { var form = this; var options = form.data('jqv'); var closingtag; if($(this).is("form")){ closingtag = "parentForm"+methods._getClassName($(this).attr("id")); }else{ closingtag = methods._getClassName($(this).attr("id")) +"formError"; } $('.'+closingtag).fadeTo(options.fadeDuration, 0.3, function() { $(this).parent('.formErrorOuter').remove(); $(this).remove(); }); return this; }, /** * Closes all error prompts on the page */ hideAll: function() { var form = this; var options = form.data('jqv'); $('.formError').fadeTo(options.fadeDuration, 0.3, function() { $(this).parent('.formErrorOuter').remove(); $(this).remove(); }); return this; },/*** Typically called when user exists a field using tab or a mouse click, triggers a field* validation*/_onFieldEvent: function(event) {var field = $(this);var form = field.closest('form');var options = form.data('jqv');// validate the current fieldwindow.setTimeout(function() {methods._validateField(field, options);if (options.InvalidFields.length == 0 && options.onSuccess) {options.onSuccess();} else if (options.InvalidFields.length > 0 && options.onFailure) {options.onFailure();}}, (event.data) ? event.data.delay : 0);},/*** Called when the form is submited, shows prompts accordingly** @param {jqObject}* form* @return false if form submission needs to be cancelled*/_onSubmitEvent: function() {var form = $(this);var options = form.data('jqv');// validate each field // (- skip field ajax validation, not necessary IF we will perform an ajax form validation)var r=methods._validateFields(form, options.ajaxFormValidation);if (r && options.ajaxFormValidation) {methods._validateFormWithAjax(form, options);return false;}if(options.onValidationComplete) {options.onValidationComplete(form, r);return false;}return r;},/*** Return true if the ajax field validations passed so far* @param {Object} options* @return true, is all ajax validation passed so far (remember ajax is async)*/_checkAjaxStatus: function(options) {var status = true;$.each(options.ajaxValidCache, function(key, value) {if (!value) {status = false;// break the eachreturn false;}});return status;},/*** Validates form fields, shows prompts accordingly** @param {jqObject}* form* @param {skipAjaxFieldValidation}* boolean - when set to true, ajax field validation is skipped, typically used when the submit button is clicked** @return true if form is valid, false if not, undefined if ajax form validation is done*/_validateFields: function(form, skipAjaxValidation) {var options = form.data('jqv');// this variable is set to true if an error is foundvar errorFound = false;// Trigger hook, start validationform.trigger("jqv.form.validating");// first, evaluate status of non ajax fieldsvar first_err=null;form.find('['+options.validateAttribute+'*=validate]').not(':hidden').not(":disabled").each( function() { var field = $(this); var names = []; if ($.inArray(field.attr('name'), names) < 0) { errorFound |= methods._validateField(field, options, skipAjaxValidation); if (options.doNotShowAllErrosOnSubmit) return false; if (errorFound && first_err==null) { first_err=field; } names.push(field.attr('name')); }});// second, check to see if all ajax calls completed ok// errorFound |= !methods._checkAjaxStatus(options);// third, check status and scroll the container accordinglyform.trigger("jqv.form.result", [errorFound]);if (errorFound) {if (options.scroll) {var destination=first_err.offset().top;var fixleft = first_err.offset().left;//prompt positioning adjustment support. Usage: positionType:Xshift,Yshift (for ex.: bottomLeft:+20 or bottomLeft:-20,+10)var positionType=options.promptPosition;if (typeof(positionType)=='string' && positionType.indexOf(":")!=-1)positionType=positionType.substring(0,positionType.indexOf(":"));if (positionType!="bottomRight" && positionType!="bottomLeft") {var prompt_err= methods._getPrompt(first_err);destination=prompt_err.offset().top;}// get the position of the first error, there should be at least one, no need to check this//var destination = form.find(".formError:not('.greenPopup'):first").offset().top;if (options.isOverflown) {var overflowDIV = $(options.overflownDIV);if(!overflowDIV.length) return false;var scrollContainerScroll = overflowDIV.scrollTop();var scrollContainerPos = -parseInt(overflowDIV.offset().top);destination += scrollContainerScroll + scrollContainerPos - 5;var scrollContainer = $(options.overflownDIV + ":not(:animated)");scrollContainer.animate({ scrollTop: destination }, 1100, function(){if(options.focusFirstField) first_err.focus();});} else {$("html:not(:animated),body:not(:animated)").animate({scrollTop: destination,scrollLeft: fixleft}, 1100, function(){if(options.focusFirstField) first_err.focus();});}} else if(options.focusFirstField)first_err.focus();return false;}return true;},/*** This method is called to perform an ajax form validation.* During this process all the (field, value) pairs are sent to the server which returns a list of invalid fields or true** @param {jqObject} form* @param {Map} options*/_validateFormWithAjax: function(form, options) {var data = form.serialize();var url = (options.ajaxFormValidationURL) ? options.ajaxFormValidationURL : form.attr("action");$.ajax({type: "GET",url: url,cache: false,dataType: "json",data: data,form: form,methods: methods,options: options,beforeSend: function() {return options.onBeforeAjaxFormValidation(form, options);},error: function(data, transport) {methods._ajaxError(data, transport);},success: function(json) {if (json !== true) {// getting to this case doesn't necessary means that the form is invalid// the server may return green or closing prompt actions// this flag helps figuring it outvar errorInForm=false;for (var i = 0; i < json.length; i++) {var value = json[i];var errorFieldId = value[0];var errorField = $($("#" + errorFieldId)[0]);// make sure we found the elementif (errorField.length == 1) {// promptText or selectorvar msg = value[2];// if the field is validif (value[1] == true) {if (msg == "" || !msg){// if for some reason, status==true and error="", just close the promptmethods._closePrompt(errorField);} else {// the field is valid, but we are displaying a green promptif (options.allrules[msg]) {var txt = options.allrules[msg].alertTextOk;if (txt)msg = txt;}methods._showPrompt(errorField, msg, "pass", false, options, true);}} else {// the field is invalid, show the red error prompterrorInForm|=true;if (options.allrules[msg]) {var txt = options.allrules[msg].alertText;if (txt)msg = txt;}methods._showPrompt(errorField, msg, "", false, options, true);}}}options.onAjaxFormComplete(!errorInForm, form, json, options);} elseoptions.onAjaxFormComplete(true, form, "", options);}});},/*** Validates field, shows prompts accordingly** @param {jqObject}* field* @param {Array[String]}* field's validation rules* @param {Map}* user options* @return true if field is valid*/_validateField: function(field, options, skipAjaxValidation) {if (!field.attr("id"))$.error("jQueryValidate: an ID attribute is required for this field: " + field.attr("name") + " class:" +field.attr("class"));var rulesParsing = field.attr(options.validateAttribute);var getRules = /validate\[(.*)\]/.exec(rulesParsing);if (!getRules)return false;var str = getRules[1];var rules = str.split(/\[|,|\]/);// true if we ran the ajax validation, tells the logic to stop messing with promptsvar isAjaxValidator = false;var fieldName = field.attr("name");var promptText = "";var required = false;options.isError = false;options.showArrow = true;var form = $(field.closest("form"));for (var i = 0; i < rules.length; i++) {// Fix for adding spaces in the rulesrules[i] = rules[i].replace(" ", "")var errorMsg = undefined;switch (rules[i]) {case "required":required = true;errorMsg = methods._required(field, rules, i, options);break;case "custom":errorMsg = methods._customRegex(field, rules, i, options);break;case "groupRequired":// Check is its the first of group, if not, reload validation with first field// AND continue normal validation on present fieldvar classGroup = "["+options.validateAttribute+"*=" +rules[i + 1] +"]";var firstOfGroup = form.find(classGroup).eq(0);if(firstOfGroup[0] != field[0]){methods._validateField(firstOfGroup, options, skipAjaxValidation)options.showArrow = true;continue;};errorMsg = methods._groupRequired(field, rules, i, options);if(errorMsg) required = true;options.showArrow = false;break;case "ajax":// ajax has its own prompts handling techniqueif(!skipAjaxValidation){methods._ajax(field, rules, i, options);isAjaxValidator = true;}break;case "minSize":errorMsg = methods._minSize(field, rules, i, options);break;case "maxSize":errorMsg = methods._maxSize(field, rules, i, options);break;case "min":errorMsg = methods._min(field, rules, i, options);break;case "max":errorMsg = methods._max(field, rules, i, options);break;case "past":errorMsg = methods._past(field, rules, i, options);break;case "future":errorMsg = methods._future(field, rules, i, options);break;case "dateRange":var classGroup = "["+options.validateAttribute+"*=" + rules[i + 1] + "]";var firstOfGroup = form.find(classGroup).eq(0);var secondOfGroup = form.find(classGroup).eq(1);//if one entry out of the pair has value then proceed to run through validationif (firstOfGroup[0].value || secondOfGroup[0].value) {errorMsg = methods._dateRange(firstOfGroup, secondOfGroup, rules, i, options);}if (errorMsg) required = true;options.showArrow = false;break;case "dateTimeRange":var classGroup = "["+options.validateAttribute+"*=" + rules[i + 1] + "]";var firstOfGroup = form.find(classGroup).eq(0);var secondOfGroup = form.find(classGroup).eq(1);//if one entry out of the pair has value then proceed to run through validationif (firstOfGroup[0].value || secondOfGroup[0].value) {errorMsg = methods._dateTimeRange(firstOfGroup, secondOfGroup, rules, i, options);}if (errorMsg) required = true;options.showArrow = false;break;case "maxCheckbox":errorMsg = methods._maxCheckbox(form, field, rules, i, options);field = $(form.find("input[name='" + fieldName + "']"));break;case "minCheckbox":errorMsg = methods._minCheckbox(form, field, rules, i, options);field = $(form.find("input[name='" + fieldName + "']"));break;case "equals":errorMsg = methods._equals(field, rules, i, options);break;case "funcCall":errorMsg = methods._funcCall(field, rules, i, options);break;case "creditCard":errorMsg = methods._creditCard(field, rules, i, options);break;default://$.error("jQueryValidator rule not found"+rules[i]);}if (errorMsg !== undefined) {promptText += errorMsg + "
";options.isError = true;}}// If the rules required is not added, an empty field is not validatedif(!required && field.val() == "") options.isError = false;// Hack for radio/checkbox group button, the validation go into the// first radio/checkbox of the groupvar fieldType = field.prop("type");if ((fieldType == "radio" || fieldType == "checkbox") && form.find("input[name='" + fieldName + "']").size() > 1) {field = $(form.find("input[name='" + fieldName + "'][type!=hidden]:first"));options.showArrow = false;}if (fieldType == "text" && form.find("input[name='" + fieldName + "']").size() > 1) {field = $(form.find("input[name='" + fieldName + "'][type!=hidden]:first"));options.showArrow = false;}if (options.isError){methods._showPrompt(field, promptText, "", false, options);}else{if (!isAjaxValidator) methods._closePrompt(field);}if (!isAjaxValidator) {field.trigger("jqv.field.result", [field, options.isError, promptText]);}/* Record error */var errindex = $.inArray(field[0], options.InvalidFields);if (errindex == -1) {if (options.isError)options.InvalidFields.push(field[0]);} else if (!options.isError) {options.InvalidFields.splice(errindex, 1);}return options.isError;},/*** Required validation** @param {jqObject} field* @param {Array[String]} rules* @param {int} i rules index* @param {Map}* user options* @return an error string if validation failed*/_required: function(field, rules, i, options) {switch (field.prop("type")) {case "text":case "password":case "textarea":case "file":default:if (!($.trim(field.val())))return options.allrules[rules[i]].alertText;break;case "radio":case "checkbox":var form = field.closest("form");var name = field.attr("name");if (form.find("input[name='" + name + "']:checked").size() == 0) {if (form.find("input[name='" + name + "']").size() == 1)return options.allrules[rules[i]].alertTextCheckboxe;elsereturn options.allrules[rules[i]].alertTextCheckboxMultiple;}break;// required for