/*! jquery validation plugin - v1.10.0 - 9/7/2012 * https://github.com/jzaefferer/jquery-validation * copyright (c) 2012 jörn zaefferer; licensed mit, gpl */ (function($) { $.extend($.fn, { // http://docs.jquery.com/plugins/validation/validate validate: function( options ) { // if nothing is selected, return nothing; can't chain anyway if (!this.length) { if (options && options.debug && window.console) { console.warn( "nothing selected, can't validate, returning nothing" ); } return; } // check if a validator for this form was already created var validator = $.data(this[0], 'validator'); if ( validator ) { return validator; } // add novalidate tag if html5. this.attr('novalidate', 'novalidate'); validator = new $.validator( options, this[0] ); $.data(this[0], 'validator', validator); if ( validator.settings.onsubmit ) { this.validatedelegate( ":submit", "click", function(ev) { if ( validator.settings.submithandler ) { validator.submitbutton = ev.target; } // allow suppressing validation by adding a cancel class to the submit button if ( $(ev.target).hasclass('cancel') ) { validator.cancelsubmit = true; } }); // validate the form on submit this.submit( function( event ) { if ( validator.settings.debug ) { // prevent form submit to be able to see console output event.preventdefault(); } function handle() { var hidden; if ( validator.settings.submithandler ) { if (validator.submitbutton) { // insert a hidden input as a replacement for the missing submit button hidden = $("").attr("name", validator.submitbutton.name).val(validator.submitbutton.value).appendto(validator.currentform); } validator.settings.submithandler.call( validator, validator.currentform, event ); if (validator.submitbutton) { // and clean up afterwards; thanks to no-block-scope, hidden can be referenced hidden.remove(); } return false; } return true; } // prevent submit for invalid forms or custom submit handlers if ( validator.cancelsubmit ) { validator.cancelsubmit = false; return handle(); } if ( validator.form() ) { if ( validator.pendingrequest ) { validator.formsubmitted = true; return false; } return handle(); } else { validator.focusinvalid(); return false; } }); } return validator; }, // http://docs.jquery.com/plugins/validation/valid valid: function() { if ( $(this[0]).is('form')) { return this.validate().form(); } else { var valid = true; var validator = $(this[0].form).validate(); this.each(function() { valid &= validator.element(this); }); return valid; } }, // attributes: space seperated list of attributes to retrieve and remove removeattrs: function(attributes) { var result = {}, $element = this; $.each(attributes.split(/\s/), function(index, value) { result[value] = $element.attr(value); $element.removeattr(value); }); return result; }, // http://docs.jquery.com/plugins/validation/rules rules: function(command, argument) { var element = this[0]; if (command) { var settings = $.data(element.form, 'validator').settings; var staticrules = settings.rules; var existingrules = $.validator.staticrules(element); switch(command) { case "add": $.extend(existingrules, $.validator.normalizerule(argument)); staticrules[element.name] = existingrules; if (argument.messages) { settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages ); } break; case "remove": if (!argument) { delete staticrules[element.name]; return existingrules; } var filtered = {}; $.each(argument.split(/\s/), function(index, method) { filtered[method] = existingrules[method]; delete existingrules[method]; }); return filtered; } } var data = $.validator.normalizerules( $.extend( {}, $.validator.metadatarules(element), $.validator.classrules(element), $.validator.attributerules(element), $.validator.staticrules(element) ), element); // make sure required is at front if (data.required) { var param = data.required; delete data.required; data = $.extend({required: param}, data); } return data; } }); // custom selectors $.extend($.expr[":"], { // http://docs.jquery.com/plugins/validation/blank blank: function(a) {return !$.trim("" + a.value);}, // http://docs.jquery.com/plugins/validation/filled filled: function(a) {return !!$.trim("" + a.value);}, // http://docs.jquery.com/plugins/validation/unchecked unchecked: function(a) {return !a.checked;} }); // constructor for validator $.validator = function( options, form ) { this.settings = $.extend( true, {}, $.validator.defaults, options ); this.currentform = form; this.init(); }; $.validator.format = function(source, params) { if ( arguments.length === 1 ) { return function() { var args = $.makearray(arguments); args.unshift(source); return $.validator.format.apply( this, args ); }; } if ( arguments.length > 2 && params.constructor !== array ) { params = $.makearray(arguments).slice(1); } if ( params.constructor !== array ) { params = [ params ]; } $.each(params, function(i, n) { source = source.replace(new regexp("\\{" + i + "\\}", "g"), n); }); return source; }; $.extend($.validator, { defaults: { messages: {}, groups: {}, rules: {}, errorclass: "error", validclass: "valid", errorelement: "label", focusinvalid: true, errorcontainer: $( [] ), errorlabelcontainer: $( [] ), onsubmit: true, ignore: ":hidden", ignoretitle: false, onfocusin: function(element, event) { this.lastactive = element; // hide error label and remove error class on focus if enabled if ( this.settings.focuscleanup && !this.blockfocuscleanup ) { if ( this.settings.unhighlight ) { this.settings.unhighlight.call( this, element, this.settings.errorclass, this.settings.validclass ); } this.addwrapper(this.errorsfor(element)).hide(); } }, onfocusout: function(element, event) { if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) { this.element(element); } }, onkeyup: function(element, event) { if ( event.which === 9 && this.elementvalue(element) === '' ) { return; } else if ( element.name in this.submitted || element === this.lastactive ) { this.element(element); } }, onclick: function(element, event) { // click on selects, radiobuttons and checkboxes if ( element.name in this.submitted ) { this.element(element); } // or option elements, check parent select in that case else if (element.parentnode.name in this.submitted) { this.element(element.parentnode); } }, highlight: function(element, errorclass, validclass) { if (element.type === 'radio') { this.findbyname(element.name).addclass(errorclass).removeclass(validclass); } else { $(element).addclass(errorclass).removeclass(validclass); } }, unhighlight: function(element, errorclass, validclass) { if (element.type === 'radio') { this.findbyname(element.name).removeclass(errorclass).addclass(validclass); } else { $(element).removeclass(errorclass).addclass(validclass); } } }, // http://docs.jquery.com/plugins/validation/validator/setdefaults setdefaults: function(settings) { $.extend( $.validator.defaults, settings ); }, messages: { required: "this field is required.", remote: "please fix this field.", email: "please enter a valid email address.", url: "please enter a valid url.", date: "please enter a valid date.", dateiso: "please enter a valid date (iso).", number: "please enter a valid number.", digits: "please enter only digits.", creditcard: "please enter a valid credit card number.", equalto: "please enter the same value again.", maxlength: $.validator.format("please enter no more than {0} characters."), minlength: $.validator.format("please enter at least {0} characters."), rangelength: $.validator.format("please enter a value between {0} and {1} characters long."), range: $.validator.format("please enter a value between {0} and {1}."), max: $.validator.format("please enter a value less than or equal to {0}."), min: $.validator.format("please enter a value greater than or equal to {0}.") }, autocreateranges: false, prototype: { init: function() { this.labelcontainer = $(this.settings.errorlabelcontainer); this.errorcontext = this.labelcontainer.length && this.labelcontainer || $(this.currentform); this.containers = $(this.settings.errorcontainer).add( this.settings.errorlabelcontainer ); this.submitted = {}; this.valuecache = {}; this.pendingrequest = 0; this.pending = {}; this.invalid = {}; this.reset(); var groups = (this.groups = {}); $.each(this.settings.groups, function(key, value) { $.each(value.split(/\s/), function(index, name) { groups[name] = key; }); }); var rules = this.settings.rules; $.each(rules, function(key, value) { rules[key] = $.validator.normalizerule(value); }); function delegate(event) { var validator = $.data(this[0].form, "validator"), eventtype = "on" + event.type.replace(/^validate/, ""); if (validator.settings[eventtype]) { validator.settings[eventtype].call(validator, this[0], event); } } $(this.currentform) .validatedelegate(":text, [type='password'], [type='file'], select, textarea, " + "[type='number'], [type='search'] ,[type='tel'], [type='url'], " + "[type='email'], [type='datetime'], [type='date'], [type='month'], " + "[type='week'], [type='time'], [type='datetime-local'], " + "[type='range'], [type='color'] ", "focusin focusout keyup", delegate) .validatedelegate("[type='radio'], [type='checkbox'], select, option", "click", delegate); if (this.settings.invalidhandler) { $(this.currentform).bind("invalid-form.validate", this.settings.invalidhandler); } }, // http://docs.jquery.com/plugins/validation/validator/form form: function() { this.checkform(); $.extend(this.submitted, this.errormap); this.invalid = $.extend({}, this.errormap); if (!this.valid()) { $(this.currentform).triggerhandler("invalid-form", [this]); } this.showerrors(); return this.valid(); }, checkform: function() { this.prepareform(); for ( var i = 0, elements = (this.currentelements = this.elements()); elements[i]; i++ ) { this.check( elements[i] ); } return this.valid(); }, // http://docs.jquery.com/plugins/validation/validator/element element: function( element ) { element = this.validationtargetfor( this.clean( element ) ); this.lastelement = element; this.prepareelement( element ); this.currentelements = $(element); var result = this.check( element ) !== false; if (result) { delete this.invalid[element.name]; } else { this.invalid[element.name] = true; } if ( !this.numberofinvalids() ) { // hide error containers on last error this.tohide = this.tohide.add( this.containers ); } this.showerrors(); return result; }, // http://docs.jquery.com/plugins/validation/validator/showerrors showerrors: function(errors) { if(errors) { // add items to error list and map $.extend( this.errormap, errors ); this.errorlist = []; for ( var name in errors ) { this.errorlist.push({ message: errors[name], element: this.findbyname(name)[0] }); } // remove items from success list this.successlist = $.grep( this.successlist, function(element) { return !(element.name in errors); }); } if (this.settings.showerrors) { this.settings.showerrors.call( this, this.errormap, this.errorlist ); } else { this.defaultshowerrors(); } }, // http://docs.jquery.com/plugins/validation/validator/resetform resetform: function() { if ( $.fn.resetform ) { $( this.currentform ).resetform(); } this.submitted = {}; this.lastelement = null; this.prepareform(); this.hideerrors(); this.elements().removeclass( this.settings.errorclass ).removedata( "previousvalue" ); }, numberofinvalids: function() { return this.objectlength(this.invalid); }, objectlength: function( obj ) { var count = 0; for ( var i in obj ) { count++; } return count; }, hideerrors: function() { this.addwrapper( this.tohide ).hide(); }, valid: function() { return this.size() === 0; }, size: function() { return this.errorlist.length; }, focusinvalid: function() { if( this.settings.focusinvalid ) { try { $(this.findlastactive() || this.errorlist.length && this.errorlist[0].element || []) .filter(":visible") .focus() // manually trigger focusin event; without it, focusin handler isn't called, findlastactive won't have anything to find .trigger("focusin"); } catch(e) { // ignore ie throwing errors when focusing hidden elements } } }, findlastactive: function() { var lastactive = this.lastactive; return lastactive && $.grep(this.errorlist, function(n) { return n.element.name === lastactive.name; }).length === 1 && lastactive; }, elements: function() { var validator = this, rulescache = {}; // select all valid inputs inside the form (no submit or reset buttons) return $(this.currentform) .find("input, select, textarea") .not(":submit, :reset, :image, [disabled]") .not( this.settings.ignore ) .filter(function() { if ( !this.name && validator.settings.debug && window.console ) { console.error( "%o has no name assigned", this); } // select only the first element for each name, and only those with rules specified if ( this.name in rulescache || !validator.objectlength($(this).rules()) ) { return false; } rulescache[this.name] = true; return true; }); }, clean: function( selector ) { return $( selector )[0]; }, errors: function() { var errorclass = this.settings.errorclass.replace(' ', '.'); return $( this.settings.errorelement + "." + errorclass, this.errorcontext ); }, reset: function() { this.successlist = []; this.errorlist = []; this.errormap = {}; this.toshow = $([]); this.tohide = $([]); this.currentelements = $([]); }, prepareform: function() { this.reset(); this.tohide = this.errors().add( this.containers ); }, prepareelement: function( element ) { this.reset(); this.tohide = this.errorsfor(element); }, elementvalue: function( element ) { var type = $(element).attr('type'), val = $(element).val(); if ( type === 'radio' || type === 'checkbox' ) { return $('input[name="' + $(element).attr('name') + '"]:checked').val(); } if ( typeof val === 'string' ) { return val.replace(/\r/g, ""); } return val; }, check: function( element ) { element = this.validationtargetfor( this.clean( element ) ); var rules = $(element).rules(); var dependencymismatch = false; var val = this.elementvalue(element); var result; for (var method in rules ) { var rule = { method: method, parameters: rules[method] }; try { result = $.validator.methods[method].call( this, val, element, rule.parameters ); // if a method indicates that the field is optional and therefore valid, // don't mark it as valid when there are no other rules if ( result === "dependency-mismatch" ) { dependencymismatch = true; continue; } dependencymismatch = false; if ( result === "pending" ) { this.tohide = this.tohide.not( this.errorsfor(element) ); return; } if( !result ) { this.formatandadd( element, rule ); return false; } } catch(e) { if ( this.settings.debug && window.console ) { console.log("exception occured when checking element " + element.id + ", check the '" + rule.method + "' method", e); } throw e; } } if (dependencymismatch) { return; } if ( this.objectlength(rules) ) { this.successlist.push(element); } return true; }, // return the custom message for the given element and validation method // specified in the element's "messages" metadata custommetamessage: function(element, method) { if (!$.metadata) { return; } var meta = this.settings.meta ? $(element).metadata()[this.settings.meta] : $(element).metadata(); return meta && meta.messages && meta.messages[method]; }, // return the custom message for the given element and validation method // specified in the element's html5 data attribute customdatamessage: function(element, method) { return $(element).data('msg-' + method.tolowercase()) || (element.attributes && $(element).attr('data-msg-' + method.tolowercase())); }, // return the custom message for the given element name and validation method custommessage: function( name, method ) { var m = this.settings.messages[name]; return m && (m.constructor === string ? m : m[method]); }, // return the first defined argument, allowing empty strings finddefined: function() { for(var i = 0; i < arguments.length; i++) { if (arguments[i] !== undefined) { return arguments[i]; } } return undefined; }, defaultmessage: function( element, method) { return this.finddefined( this.custommessage( element.name, method ), this.customdatamessage( element, method ), this.custommetamessage( element, method ), // title is never undefined, so handle empty string as undefined !this.settings.ignoretitle && element.title || undefined, $.validator.messages[method], "warning: no message defined for " + element.name + "" ); }, formatandadd: function( element, rule ) { var message = this.defaultmessage( element, rule.method ), theregex = /\$?\{(\d+)\}/g; if ( typeof message === "function" ) { message = message.call(this, rule.parameters, element); } else if (theregex.test(message)) { message = $.validator.format(message.replace(theregex, '{$1}'), rule.parameters); } this.errorlist.push({ message: message, element: element }); this.errormap[element.name] = message; this.submitted[element.name] = message; }, addwrapper: function(totoggle) { if ( this.settings.wrapper ) { totoggle = totoggle.add( totoggle.parent( this.settings.wrapper ) ); } return totoggle; }, defaultshowerrors: function() { var i, elements; for ( i = 0; this.errorlist[i]; i++ ) { var error = this.errorlist[i]; if ( this.settings.highlight ) { this.settings.highlight.call( this, error.element, this.settings.errorclass, this.settings.validclass ); } this.showlabel( error.element, error.message ); } if( this.errorlist.length ) { this.toshow = this.toshow.add( this.containers ); } if (this.settings.success) { for ( i = 0; this.successlist[i]; i++ ) { this.showlabel( this.successlist[i] ); } } if (this.settings.unhighlight) { for ( i = 0, elements = this.validelements(); elements[i]; i++ ) { this.settings.unhighlight.call( this, elements[i], this.settings.errorclass, this.settings.validclass ); } } this.tohide = this.tohide.not( this.toshow ); this.hideerrors(); this.addwrapper( this.toshow ).show(); }, validelements: function() { return this.currentelements.not(this.invalidelements()); }, invalidelements: function() { return $(this.errorlist).map(function() { return this.element; }); }, showlabel: function(element, message) { var label = this.errorsfor( element ); if ( label.length ) { // refresh error/success class label.removeclass( this.settings.validclass ).addclass( this.settings.errorclass ); // check if we have a generated label, replace the message then if ( label.attr("generated") ) { label.html(message); } } else { // create label label = $("<" + this.settings.errorelement + "/>") .attr({"for": this.idorname(element), generated: true}) .addclass(this.settings.errorclass) .html(message || ""); if ( this.settings.wrapper ) { // make sure the element is visible, even in ie // actually showing the wrapped element is handled elsewhere label = label.hide().show().wrap("<" + this.settings.wrapper + "/>").parent(); } if ( !this.labelcontainer.append(label).length ) { if ( this.settings.errorplacement ) { this.settings.errorplacement(label, $(element) ); } else { label.insertafter(element); } } } if ( !message && this.settings.success ) { label.text(""); if ( typeof this.settings.success === "string" ) { label.addclass( this.settings.success ); } else { this.settings.success( label, element ); } } this.toshow = this.toshow.add(label); }, errorsfor: function(element) { var name = this.idorname(element); return this.errors().filter(function() { return $(this).attr('for') === name; }); }, idorname: function(element) { return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name); }, validationtargetfor: function(element) { // if radio/checkbox, validate first element in group instead if (this.checkable(element)) { element = this.findbyname( element.name ).not(this.settings.ignore)[0]; } return element; }, checkable: function( element ) { return (/radio|checkbox/i).test(element.type); }, findbyname: function( name ) { return $(this.currentform).find('[name="' + name + '"]'); }, getlength: function(value, element) { switch( element.nodename.tolowercase() ) { case 'select': return $("option:selected", element).length; case 'input': if( this.checkable( element) ) { return this.findbyname(element.name).filter(':checked').length; } } return value.length; }, depend: function(param, element) { return this.dependtypes[typeof param] ? this.dependtypes[typeof param](param, element) : true; }, dependtypes: { "boolean": function(param, element) { return param; }, "string": function(param, element) { return !!$(param, element.form).length; }, "function": function(param, element) { return param(element); } }, optional: function(element) { var val = this.elementvalue(element); return !$.validator.methods.required.call(this, val, element) && "dependency-mismatch"; }, startrequest: function(element) { if (!this.pending[element.name]) { this.pendingrequest++; this.pending[element.name] = true; } }, stoprequest: function(element, valid) { this.pendingrequest--; // sometimes synchronization fails, make sure pendingrequest is never < 0 if (this.pendingrequest < 0) { this.pendingrequest = 0; } delete this.pending[element.name]; if ( valid && this.pendingrequest === 0 && this.formsubmitted && this.form() ) { $(this.currentform).submit(); this.formsubmitted = false; } else if (!valid && this.pendingrequest === 0 && this.formsubmitted) { $(this.currentform).triggerhandler("invalid-form", [this]); this.formsubmitted = false; } }, previousvalue: function(element) { return $.data(element, "previousvalue") || $.data(element, "previousvalue", { old: null, valid: true, message: this.defaultmessage( element, "remote" ) }); } }, classrulesettings: { required: {required: true}, email: {email: true}, url: {url: true}, date: {date: true}, dateiso: {dateiso: true}, number: {number: true}, digits: {digits: true}, creditcard: {creditcard: true} }, addclassrules: function(classname, rules) { if ( classname.constructor === string ) { this.classrulesettings[classname] = rules; } else { $.extend(this.classrulesettings, classname); } }, classrules: function(element) { var rules = {}; var classes = $(element).attr('class'); if ( classes ) { $.each(classes.split(' '), function() { if (this in $.validator.classrulesettings) { $.extend(rules, $.validator.classrulesettings[this]); } }); } return rules; }, attributerules: function(element) { var rules = {}; var $element = $(element); for (var method in $.validator.methods) { var value; // support for in both html5 and older browsers if (method === 'required') { value = $element.get(0).getattribute(method); // some browsers return an empty string for the required attribute // and non-html5 browsers might have required="" markup if (value === "") { value = true; } // force non-html5 browsers to return bool value = !!value; } else { value = $element.attr(method); } if (value) { rules[method] = value; } else if ($element[0].getattribute("type") === method) { rules[method] = true; } } // maxlength may be returned as -1, 2147483647 (ie) and 524288 (safari) for text inputs if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) { delete rules.maxlength; } return rules; }, metadatarules: function(element) { if (!$.metadata) { return {}; } var meta = $.data(element.form, 'validator').settings.meta; return meta ? $(element).metadata()[meta] : $(element).metadata(); }, staticrules: function(element) { var rules = {}; var validator = $.data(element.form, 'validator'); if (validator.settings.rules) { rules = $.validator.normalizerule(validator.settings.rules[element.name]) || {}; } return rules; }, normalizerules: function(rules, element) { // handle dependency check $.each(rules, function(prop, val) { // ignore rule when param is explicitly false, eg. required:false if (val === false) { delete rules[prop]; return; } if (val.param || val.depends) { var keeprule = true; switch (typeof val.depends) { case "string": keeprule = !!$(val.depends, element.form).length; break; case "function": keeprule = val.depends.call(element, element); break; } if (keeprule) { rules[prop] = val.param !== undefined ? val.param : true; } else { delete rules[prop]; } } }); // evaluate parameters $.each(rules, function(rule, parameter) { rules[rule] = $.isfunction(parameter) ? parameter(element) : parameter; }); // clean number parameters $.each(['minlength', 'maxlength', 'min', 'max'], function() { if (rules[this]) { rules[this] = number(rules[this]); } }); $.each(['rangelength', 'range'], function() { if (rules[this]) { rules[this] = [number(rules[this][0]), number(rules[this][1])]; } }); if ($.validator.autocreateranges) { // auto-create ranges if (rules.min && rules.max) { rules.range = [rules.min, rules.max]; delete rules.min; delete rules.max; } if (rules.minlength && rules.maxlength) { rules.rangelength = [rules.minlength, rules.maxlength]; delete rules.minlength; delete rules.maxlength; } } // to support custom messages in metadata ignore rule methods titled "messages" if (rules.messages) { delete rules.messages; } return rules; }, // converts a simple string to a {string: true} rule, e.g., "required" to {required:true} normalizerule: function(data) { if( typeof data === "string" ) { var transformed = {}; $.each(data.split(/\s/), function() { transformed[this] = true; }); data = transformed; } return data; }, // http://docs.jquery.com/plugins/validation/validator/addmethod addmethod: function(name, method, message) { $.validator.methods[name] = method; $.validator.messages[name] = message !== undefined ? message : $.validator.messages[name]; if (method.length < 3) { $.validator.addclassrules(name, $.validator.normalizerule(name)); } }, methods: { // http://docs.jquery.com/plugins/validation/methods/required required: function(value, element, param) { // check if dependency is met if ( !this.depend(param, element) ) { return "dependency-mismatch"; } if ( element.nodename.tolowercase() === "select" ) { // could be an array for select-multiple or a string, both are fine this way var val = $(element).val(); return val && val.length > 0; } if ( this.checkable(element) ) { return this.getlength(value, element) > 0; } return $.trim(value).length > 0; }, // http://docs.jquery.com/plugins/validation/methods/remote remote: function(value, element, param) { if ( this.optional(element) ) { return "dependency-mismatch"; } var previous = this.previousvalue(element); if (!this.settings.messages[element.name] ) { this.settings.messages[element.name] = {}; } previous.originalmessage = this.settings.messages[element.name].remote; this.settings.messages[element.name].remote = previous.message; param = typeof param === "string" && {url:param} || param; if ( this.pending[element.name] ) { return "pending"; } if ( previous.old === value ) { return previous.valid; } previous.old = value; var validator = this; this.startrequest(element); var data = {}; data[element.name] = value; $.ajax($.extend(true, { url: param, mode: "abort", port: "validate" + element.name, datatype: "json", data: data, success: function(response) { validator.settings.messages[element.name].remote = previous.originalmessage; var valid = response === true || response === "true"; if ( valid ) { var submitted = validator.formsubmitted; validator.prepareelement(element); validator.formsubmitted = submitted; validator.successlist.push(element); delete validator.invalid[element.name]; validator.showerrors(); } else { var errors = {}; var message = response || validator.defaultmessage( element, "remote" ); errors[element.name] = previous.message = $.isfunction(message) ? message(value) : message; validator.invalid[element.name] = true; validator.showerrors(errors); } previous.valid = valid; validator.stoprequest(element, valid); } }, param)); return "pending"; }, // http://docs.jquery.com/plugins/validation/methods/minlength minlength: function(value, element, param) { var length = $.isarray( value ) ? value.length : this.getlength($.trim(value), element); return this.optional(element) || length >= param; }, // http://docs.jquery.com/plugins/validation/methods/maxlength maxlength: function(value, element, param) { var length = $.isarray( value ) ? value.length : this.getlength($.trim(value), element); return this.optional(element) || length <= param; }, // http://docs.jquery.com/plugins/validation/methods/rangelength rangelength: function(value, element, param) { var length = $.isarray( value ) ? value.length : this.getlength($.trim(value), element); return this.optional(element) || ( length >= param[0] && length <= param[1] ); }, // http://docs.jquery.com/plugins/validation/methods/min min: function( value, element, param ) { return this.optional(element) || value >= param; }, // http://docs.jquery.com/plugins/validation/methods/max max: function( value, element, param ) { return this.optional(element) || value <= param; }, // http://docs.jquery.com/plugins/validation/methods/range range: function( value, element, param ) { return this.optional(element) || ( value >= param[0] && value <= param[1] ); }, // http://docs.jquery.com/plugins/validation/methods/email email: function(value, element) { // contributed by scott gonzalez: http://projects.scottsplayground.com/email_address_validation/ 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); }, // http://docs.jquery.com/plugins/validation/methods/url url: function(value, element) { // contributed by scott gonzalez: http://projects.scottsplayground.com/iri/ 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); }, // http://docs.jquery.com/plugins/validation/methods/date date: function(value, element) { return this.optional(element) || !/invalid|nan/.test(new date(value)); }, // http://docs.jquery.com/plugins/validation/methods/dateiso dateiso: function(value, element) { return this.optional(element) || /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/.test(value); }, // http://docs.jquery.com/plugins/validation/methods/number number: function(value, element) { return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(value); }, // http://docs.jquery.com/plugins/validation/methods/digits digits: function(value, element) { return this.optional(element) || /^\d+$/.test(value); }, // http://docs.jquery.com/plugins/validation/methods/creditcard // based on http://en.wikipedia.org/wiki/luhn creditcard: function(value, element) { if ( this.optional(element) ) { return "dependency-mismatch"; } // accept only spaces, digits and dashes if (/[^0-9 \-]+/.test(value)) { return false; } var ncheck = 0, ndigit = 0, beven = false; value = value.replace(/\d/g, ""); for (var n = value.length - 1; n >= 0; n--) { var cdigit = value.charat(n); ndigit = parseint(cdigit, 10); if (beven) { if ((ndigit *= 2) > 9) { ndigit -= 9; } } ncheck += ndigit; beven = !beven; } return (ncheck % 10) === 0; }, // http://docs.jquery.com/plugins/validation/methods/equalto equalto: function(value, element, param) { // bind to the blur event of the target in order to revalidate whenever the target field is updated // todo find a way to bind the event just once, avoiding the unbind-rebind overhead var target = $(param); if (this.settings.onfocusout) { target.unbind(".validate-equalto").bind("blur.validate-equalto", function() { $(element).valid(); }); } return value === target.val(); } } }); // deprecated, use $.validator.format instead $.format = $.validator.format; }(jquery)); // ajax mode: abort // usage: $.ajax({ mode: "abort"[, port: "uniqueport"]}); // if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via xmlhttprequest.abort() (function($) { var pendingrequests = {}; // use a prefilter if available (1.5+) if ( $.ajaxprefilter ) { $.ajaxprefilter(function(settings, _, xhr) { var port = settings.port; if (settings.mode === "abort") { if ( pendingrequests[port] ) { pendingrequests[port].abort(); } pendingrequests[port] = xhr; } }); } else { // proxy ajax var ajax = $.ajax; $.ajax = function(settings) { var mode = ( "mode" in settings ? settings : $.ajaxsettings ).mode, port = ( "port" in settings ? settings : $.ajaxsettings ).port; if (mode === "abort") { if ( pendingrequests[port] ) { pendingrequests[port].abort(); } return (pendingrequests[port] = ajax.apply(this, arguments)); } return ajax.apply(this, arguments); }; } }(jquery)); // provides cross-browser focusin and focusout events // ie has native support, in other browsers, use event caputuring (neither bubbles) // provides delegate(type: string, delegate: selector, handler: callback) plugin for easier event delegation // handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target (function($) { // only implement if not provided by jquery core (since 1.4) // todo verify if jquery 1.4's implementation is compatible with older jquery special-event apis if (!jquery.event.special.focusin && !jquery.event.special.focusout && document.addeventlistener) { $.each({ focus: 'focusin', blur: 'focusout' }, function( original, fix ){ $.event.special[fix] = { setup:function() { this.addeventlistener( original, handler, true ); }, teardown:function() { this.removeeventlistener( original, handler, true ); }, handler: function(e) { var args = arguments; args[0] = $.event.fix(e); args[0].type = fix; return $.event.handle.apply(this, args); } }; function handler(e) { e = $.event.fix(e); e.type = fix; return $.event.handle.call(this, e); } }); } $.extend($.fn, { validatedelegate: function(delegate, type, handler) { return this.bind(type, function(event) { var target = $(event.target); if (target.is(delegate)) { return handler.apply(target, arguments); } }); } }); }(jquery)); $.validator.addmethod("mask", function(value, element, param){ if ($.trim(value) == "") { return true; } return param.test(value); });