/* * jquery validation plug-in 1.5.5 * * http://bassistance.de/jquery-plugins/jquery-plugin-validation/ * http://docs.jquery.com/plugins/validation * * copyright (c) 2006 - 2008 jörn zaefferer * * $id: jquery.validate.js 6403 2009-06-17 14:27:16z joern.zaefferer $ * * dual licensed under the mit and gpl licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html */ (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) { 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; } validator = new $.validator( options, this[0] ); $.data(this[0], 'validator', validator); if ( validator.settings.onsubmit ) { // allow suppresing validation by adding a cancel class to the submit button this.find("input, button").filter(".cancel").click(function() { validator.cancelsubmit = true; }); // when a submithandler is used, capture the submitting button if (validator.settings.submithandler) { this.find("input, button").filter(":submit").click(function() { validator.submitbutton = this; }); } // 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() { if ( validator.settings.submithandler ) { if (validator.submitbutton) { // insert a hidden input as a replacement for the missing submit button var hidden = $("").attr("name", validator.submitbutton.name).val(validator.submitbutton.value).appendto(validator.currentform); } validator.settings.submithandler.call( validator, validator.currentform ); 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( {}, $.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: "span", focusinvalid: true, errorcontainer: $( [] ), errorlabelcontainer: $( [] ), onsubmit: true, ignore: [], ignoretitle: false, onfocusin: function(element) { this.lastactive = element; // hide error label and remove error class on focus if enabled if ( this.settings.focuscleanup && !this.blockfocuscleanup ) { this.settings.unhighlight && this.settings.unhighlight.call( this, element, this.settings.errorclass, this.settings.validclass ); this.errorsfor(element).hide(); } }, onfocusout: function(element) { if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) { this.element(element); } }, onkeyup: function(element) { if ( element.name in this.submitted || element == this.lastelement ) { this.element(element); } }, onclick: function(element) { if ( element.name in this.submitted ) this.element(element); }, highlight: function( element, errorclass, validclass ) { $(element).addclass(errorclass).removeclass(validclass); }, unhighlight: function( element, errorclass, validclass ) { $(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).", datede: "bitte geben sie ein gültiges datum ein.", number: "please enter a valid number.", numberde: "bitte geben sie eine nummer ein.", digits: "please enter only digits", creditcard: "please enter a valid credit card number.", equalto: "please enter the same value again.", accept: "please enter a value with a valid extension.", 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"); validator.settings["on" + event.type] && validator.settings["on" + event.type].call(validator, this[0] ); } $(this.currentform) .delegate("focusin focusout keyup", ":text, :password, :file, select, textarea", delegate) .delegate("click", ":radio, :checkbox", 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.clean( element ); this.lastelement = element; this.prepareelement( element ); this.currentelements = $(element); var result = this.check( element ); 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); }); } this.settings.showerrors ? this.settings.showerrors.call( this, this.errormap, this.errorlist ) : this.defaultshowerrors(); }, // http://docs.jquery.com/plugins/validation/validator/resetform resetform: function() { if ( $.fn.resetform ) $( this.currentform ).resetform(); this.submitted = {}; this.prepareform(); this.hideerrors(); this.elements().removeclass( this.settings.errorclass ); }, 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(); } 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) // workaround $query([]).add until http://dev.jquery.com/ticket/2114 is solved return $([]).add(this.currentform.elements) .filter(":input") .not(":submit, :reset, :image, [disabled]") .not( this.settings.ignore ) .filter(function() { !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() { return $( this.settings.errorelement + "." + this.settings.errorclass, this.errorcontext ); }, reset: function() { this.successlist = []; this.errorlist = []; this.errormap = {}; this.toshow = $([]); this.tohide = $([]); this.formsubmitted = false; this.currentelements = $([]); }, prepareform: function() { this.reset(); this.tohide = this.errors().add( this.containers ); }, prepareelement: function( element ) { this.reset(); this.tohide = this.errorsfor(element); }, check: function( element ) { element = this.clean( element ); // if radio/checkbox, validate first element in group instead if (this.checkable(element)) { element = this.findbyname( element.name )[0]; } var rules = $(element).rules(); var dependencymismatch = false; for( method in rules ) { var rule = { method: method, parameters: rules[method] }; try { var result = $.validator.methods[method].call( this, element.value.replace(/\r/g, ""), 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) { this.settings.debug && window.console && console.log("exception occured when checking element " + element.id + ", check the '" + rule.method + "' method"); 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 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.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 ); if ( typeof message == "function" ) message = message.call(this, rule.parameters, element); 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() { for ( var i = 0; this.errorlist[i]; i++ ) { var error = this.errorlist[i]; 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 ( var i = 0; this.successlist[i]; i++ ) { this.showlabel( this.successlist[i] ); } } if (this.settings.unhighlight) { for ( var 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().addclass( this.settings.errorclass ); // check if we have a generated label, replace the message then 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 ) this.settings.errorplacement ? this.settings.errorplacement(label, $(element) ) : label.insertafter(element); } if ( !message && this.settings.success ) { label.text(""); typeof this.settings.success == "string" ? label.addclass( this.settings.success ) : this.settings.success( label ); } this.toshow = this.toshow.add(label); }, errorsfor: function(element) { return this.errors().filter("[for='" + this.idorname(element) + "']"); }, idorname: function(element) { return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name); }, checkable: function( element ) { return /radio|checkbox/i.test(element.type); }, findbyname: function( name ) { // select by name and filter by form for performance over form.find("[name=...]") var form = this.currentform; return $(document.getelementsbyname(name)).map(function(index, element) { return element.form == form && element.name == name && element || null; }); }, 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) { return !$.validator.methods.required.call(this, $.trim(element.value), 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(); } else if (!valid && this.pendingrequest == 0 && this.formsubmitted) { $(this.currentform).triggerhandler("invalid-form", [this]); } }, previousvalue: function(element) { return $.data(element, "previousvalue") || $.data(element, "previousvalue", previous = { 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}, datede: {datede: true}, number: {number: true}, numberde: {numberde: true}, digits: {digits: true}, creditcard: {creditcard: true} }, addclassrules: function(classname, rules) { classname.constructor == string ? this.classrulesettings[classname] = rules : $.extend(this.classrulesettings, classname); }, classrules: function(element) { var rules = {}; var classes = $(element).attr('class'); 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 (method in $.validator.methods) { var value = $element.attr(method); if (value) { rules[method] = value; } } // 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 || $.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"; switch( element.nodename.tolowercase() ) { case 'select': var options = $("option:selected", element); return options.length > 0 && ( element.type == "select-multiple" || ($.browser.msie && !(options[0].attributes['value'].specified) ? options[0].text : options[0].value).length > 0); case 'input': if ( this.checkable(element) ) return this.getlength(value, element) > 0; default: 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] = {}; this.settings.messages[element.name].remote = typeof previous.message == "function" ? previous.message(value) : previous.message; param = typeof param == "string" && {url:param} || param; if ( previous.old !== value ) { 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) { var valid = response === true; if ( valid ) { var submitted = validator.formsubmitted; validator.prepareelement(element); validator.formsubmitted = submitted; validator.successlist.push(element); validator.showerrors(); } else { var errors = {}; errors[element.name] = previous.message = response || validator.defaultmessage( element, "remote" ); validator.showerrors(errors); } previous.valid = valid; validator.stoprequest(element, valid); } }, param)); return "pending"; } else if( this.pending[element.name] ) { return "pending"; } return previous.valid; }, // http://docs.jquery.com/plugins/validation/methods/minlength minlength: function(value, element, param) { return this.optional(element) || this.getlength($.trim(value), element) >= param; }, // http://docs.jquery.com/plugins/validation/methods/maxlength maxlength: function(value, element, param) { return this.optional(element) || this.getlength($.trim(value), element) <= param; }, // http://docs.jquery.com/plugins/validation/methods/rangelength rangelength: function(value, element, param) { var 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/datede datede: function(value, element) { return this.optional(element) || /^\d\d?\.\d\d?\.\d\d\d?\d?$/.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/numberde numberde: 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 digits and dashes if (/[^0-9-]+/.test(value)) return false; var ncheck = 0, ndigit = 0, beven = false; value = value.replace(/\d/g, ""); for (n = value.length - 1; n >= 0; n--) { var cdigit = value.charat(n); var 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/accept accept: function(value, element, param) { param = typeof param == "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif"; return this.optional(element) || value.match(new regexp(".(" + param + ")$", "i")); }, // http://docs.jquery.com/plugins/validation/methods/equalto equalto: function(value, element, param) { return value == $(param).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 ajax = $.ajax; var pendingrequests = {}; $.ajax = function(settings) { // create settings for compatibility with ajaxsetup settings = $.extend(settings, $.extend({}, $.ajaxsettings, settings)); var port = settings.port; if (settings.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 // provides triggerevent(type: string, target: element) to trigger delegated events ;(function($) { $.each({ focus: 'focusin', blur: 'focusout' }, function( original, fix ){ $.event.special[fix] = { setup:function() { if ( $.browser.msie ) return false; this.addeventlistener( original, $.event.special[fix].handler, true ); }, teardown:function() { if ( $.browser.msie ) return false; this.removeeventlistener( original, $.event.special[fix].handler, true ); }, handler: function(e) { arguments[0] = $.event.fix(e); arguments[0].type = fix; return $.event.handle.apply(this, arguments); } }; }); $.extend($.fn, { delegate: function(type, delegate, handler) { return this.bind(type, function(event) { var target = $(event.target); if (target.is(delegate)) { return handler.apply(target, arguments); } }); }, triggerevent: function(type, target) { return this.triggerhandler(type, [$.event.fix({ type: type, target: target })]); } }) })(jquery);