1 /* NUGET: BEGIN LICENSE TEXT
3 * Microsoft grants you the right to use these script files for the sole
4 * purpose of either: (i) interacting through your browser with the Microsoft
5 * website or online service, subject to the applicable licensing or use
6 * terms; or (ii) using the files as included with a Microsoft product subject
7 * to that product's license terms. Microsoft reserves all other rights to the
8 * files not expressly granted by Microsoft, whether by implication, estoppel
9 * or otherwise. Insofar as a script file is dual licensed under GPL,
10 * Microsoft neither took the code under GPL nor distributes it thereunder but
11 * under the terms set out in this paragraph. All notices and licenses
12 * below are for informational purposes only.
14 * NUGET: END LICENSE TEXT */
16 * This file has been commented to support Visual Studio Intellisense.
17 * You should not use this file at runtime inside the browser--it is only
18 * intended to be used only for design-time IntelliSense. Please use the
19 * standard jQuery library for all production use.
21 * Comment version: 1.11.1
25 * Note: While Microsoft is not the author of this file, Microsoft is
26 * offering you a license subject to the terms of the Microsoft Software
27 * License Terms for Microsoft ASP.NET Model View Controller 3.
28 * Microsoft reserves all other rights. The notices below are provided
29 * for informational purposes only and are not the license terms under
30 * which Microsoft distributed this file.
32 * jQuery Validation Plugin - v1.11.1 - 2/4/2013
33 * https://github.com/jzaefferer/jquery-validation
34 * Copyright (c) 2013 Jörn Zaefferer; Licensed MIT
41 // http://docs.jquery.com/Plugins/Validation/validate
42 validate: function( options ) {
44 /// Validates the selected form. This method sets up event handlers for submit, focus,
45 /// keyup, blur and click to trigger validation of the entire form or individual
46 /// elements. Each one can be disabled, see the onxxx options (onsubmit, onfocusout,
47 /// onkeyup, onclick). focusInvalid focuses elements when submitting a invalid form.
49 /// <param name="options" type="Object">
50 /// A set of key/value pairs that configure the validate. All options are optional.
53 // if nothing is selected, return nothing; can't chain anyway
55 options && options.debug && window.console && console.warn( "nothing selected, can't validate, returning nothing" );
59 // check if a validator for this form was already created
60 var validator = $.data(this[0], 'validator');
65 validator = new $.validator( options, this[0] );
66 $.data(this[0], 'validator', validator);
68 if ( validator.settings.onsubmit ) {
70 // allow suppresing validation by adding a cancel class to the submit button
71 this.find("input, button").filter(".cancel").click(function() {
72 validator.cancelSubmit = true;
75 // when a submitHandler is used, capture the submitting button
76 if (validator.settings.submitHandler) {
77 this.find("input, button").filter(":submit").click(function() {
78 validator.submitButton = this;
82 // validate the form on submit
83 this.submit( function( event ) {
84 if ( validator.settings.debug )
85 // prevent form submit to be able to see console output
86 event.preventDefault();
89 if ( validator.settings.submitHandler ) {
90 if (validator.submitButton) {
91 // insert a hidden input as a replacement for the missing submit button
92 var hidden = $("<input type='hidden'/>").attr("name", validator.submitButton.name).val(validator.submitButton.value).appendTo(validator.currentForm);
94 validator.settings.submitHandler.call( validator, validator.currentForm );
95 if (validator.submitButton) {
96 // and clean up afterwards; thanks to no-block-scope, hidden can be referenced
104 // prevent submit for invalid forms or custom submit handlers
105 if ( validator.cancelSubmit ) {
106 validator.cancelSubmit = false;
109 if ( validator.form() ) {
110 if ( validator.pendingRequest ) {
111 validator.formSubmitted = true;
116 validator.focusInvalid();
124 // http://docs.jquery.com/Plugins/Validation/valid
127 /// Checks if the selected form is valid or if all selected elements are valid.
128 /// validate() needs to be called on the form before checking it using this method.
130 /// <returns type="Boolean" />
132 if ( $(this[0]).is('form')) {
133 return this.validate().form();
136 var validator = $(this[0].form).validate();
137 this.each(function() {
138 valid &= validator.element(this);
143 // attributes: space seperated list of attributes to retrieve and remove
144 removeAttrs: function(attributes) {
146 /// Remove the specified attributes from the first matched element and return them.
148 /// <param name="attributes" type="String">
149 /// A space-seperated list of attribute names to remove.
154 $.each(attributes.split(/\s/), function(index, value) {
155 result[value] = $element.attr(value);
156 $element.removeAttr(value);
160 // http://docs.jquery.com/Plugins/Validation/rules
161 rules: function(command, argument) {
163 /// Return the validations rules for the first selected element.
165 /// <param name="command" type="String">
166 /// Can be either "add" or "remove".
168 /// <param name="argument" type="">
169 /// A list of rules to add or remove.
172 var element = this[0];
175 var settings = $.data(element.form, 'validator').settings;
176 var staticRules = settings.rules;
177 var existingRules = $.validator.staticRules(element);
180 $.extend(existingRules, $.validator.normalizeRule(argument));
181 staticRules[element.name] = existingRules;
182 if (argument.messages)
183 settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages );
187 delete staticRules[element.name];
188 return existingRules;
191 $.each(argument.split(/\s/), function(index, method) {
192 filtered[method] = existingRules[method];
193 delete existingRules[method];
199 var data = $.validator.normalizeRules(
202 $.validator.metadataRules(element),
203 $.validator.classRules(element),
204 $.validator.attributeRules(element),
205 $.validator.staticRules(element)
208 // make sure required is at front
210 var param = data.required;
211 delete data.required;
212 data = $.extend({required: param}, data);
220 $.extend($.expr[":"], {
221 // http://docs.jquery.com/Plugins/Validation/blank
222 blank: function(a) {return !$.trim("" + a.value);},
223 // http://docs.jquery.com/Plugins/Validation/filled
224 filled: function(a) {return !!$.trim("" + a.value);},
225 // http://docs.jquery.com/Plugins/Validation/unchecked
226 unchecked: function(a) {return !a.checked;}
229 // constructor for validator
230 $.validator = function( options, form ) {
231 this.settings = $.extend( true, {}, $.validator.defaults, options );
232 this.currentForm = form;
236 $.validator.format = function(source, params) {
238 /// Replaces {n} placeholders with arguments.
239 /// One or more arguments can be passed, in addition to the string template itself, to insert
242 /// <param name="source" type="String">
243 /// The string to format.
245 /// <param name="params" type="String">
246 /// The first argument to insert, or an array of Strings to insert
248 /// <returns type="String" />
250 if ( arguments.length == 1 )
252 var args = $.makeArray(arguments);
253 args.unshift(source);
254 return $.validator.format.apply( this, args );
256 if ( arguments.length > 2 && params.constructor != Array ) {
257 params = $.makeArray(arguments).slice(1);
259 if ( params.constructor != Array ) {
262 $.each(params, function(i, n) {
263 source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
268 $.extend($.validator, {
276 errorElement: "label",
278 errorContainer: $( [] ),
279 errorLabelContainer: $( [] ),
283 onfocusin: function(element) {
284 this.lastActive = element;
286 // hide error label and remove error class on focus if enabled
287 if ( this.settings.focusCleanup && !this.blockFocusCleanup ) {
288 this.settings.unhighlight && this.settings.unhighlight.call( this, element, this.settings.errorClass, this.settings.validClass );
289 this.addWrapper(this.errorsFor(element)).hide();
292 onfocusout: function(element) {
293 if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) {
294 this.element(element);
297 onkeyup: function(element) {
298 if ( element.name in this.submitted || element == this.lastElement ) {
299 this.element(element);
302 onclick: function(element) {
303 // click on selects, radiobuttons and checkboxes
304 if ( element.name in this.submitted )
305 this.element(element);
306 // or option elements, check parent select in that case
307 else if (element.parentNode.name in this.submitted)
308 this.element(element.parentNode);
310 highlight: function( element, errorClass, validClass ) {
311 $(element).addClass(errorClass).removeClass(validClass);
313 unhighlight: function( element, errorClass, validClass ) {
314 $(element).removeClass(errorClass).addClass(validClass);
318 // http://docs.jquery.com/Plugins/Validation/Validator/setDefaults
319 setDefaults: function(settings) {
321 /// Modify default settings for validation.
322 /// Accepts everything that Plugins/Validation/validate accepts.
324 /// <param name="settings" type="Options">
325 /// Options to set as default.
328 $.extend( $.validator.defaults, settings );
332 required: "This field is required.",
333 remote: "Please fix this field.",
334 email: "Please enter a valid email address.",
335 url: "Please enter a valid URL.",
336 date: "Please enter a valid date.",
337 dateISO: "Please enter a valid date (ISO).",
338 number: "Please enter a valid number.",
339 digits: "Please enter only digits.",
340 creditcard: "Please enter a valid credit card number.",
341 equalTo: "Please enter the same value again.",
342 accept: "Please enter a value with a valid extension.",
343 maxlength: $.validator.format("Please enter no more than {0} characters."),
344 minlength: $.validator.format("Please enter at least {0} characters."),
345 rangelength: $.validator.format("Please enter a value between {0} and {1} characters long."),
346 range: $.validator.format("Please enter a value between {0} and {1}."),
347 max: $.validator.format("Please enter a value less than or equal to {0}."),
348 min: $.validator.format("Please enter a value greater than or equal to {0}.")
351 autoCreateRanges: false,
356 this.labelContainer = $(this.settings.errorLabelContainer);
357 this.errorContext = this.labelContainer.length && this.labelContainer || $(this.currentForm);
358 this.containers = $(this.settings.errorContainer).add( this.settings.errorLabelContainer );
360 this.valueCache = {};
361 this.pendingRequest = 0;
366 var groups = (this.groups = {});
367 $.each(this.settings.groups, function(key, value) {
368 $.each(value.split(/\s/), function(index, name) {
372 var rules = this.settings.rules;
373 $.each(rules, function(key, value) {
374 rules[key] = $.validator.normalizeRule(value);
377 function delegate(event) {
378 var validator = $.data(this[0].form, "validator"),
379 eventType = "on" + event.type.replace(/^validate/, "");
380 validator.settings[eventType] && validator.settings[eventType].call(validator, this[0] );
383 .validateDelegate(":text, :password, :file, select, textarea", "focusin focusout keyup", delegate)
384 .validateDelegate(":radio, :checkbox, select, option", "click", delegate);
386 if (this.settings.invalidHandler)
387 $(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler);
390 // http://docs.jquery.com/Plugins/Validation/Validator/form
393 /// Validates the form, returns true if it is valid, false otherwise.
394 /// This behaves as a normal submit event, but returns the result.
396 /// <returns type="Boolean" />
399 $.extend(this.submitted, this.errorMap);
400 this.invalid = $.extend({}, this.errorMap);
402 $(this.currentForm).triggerHandler("invalid-form", [this]);
407 checkForm: function() {
409 for ( var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++ ) {
410 this.check( elements[i] );
415 // http://docs.jquery.com/Plugins/Validation/Validator/element
416 element: function( element ) {
418 /// Validates a single element, returns true if it is valid, false otherwise.
419 /// This behaves as validation on blur or keyup, but returns the result.
421 /// <param name="element" type="Selector">
422 /// An element to validate, must be inside the validated form.
424 /// <returns type="Boolean" />
426 element = this.clean( element );
427 this.lastElement = element;
428 this.prepareElement( element );
429 this.currentElements = $(element);
430 var result = this.check( element );
432 delete this.invalid[element.name];
434 this.invalid[element.name] = true;
436 if ( !this.numberOfInvalids() ) {
437 // Hide error containers on last error
438 this.toHide = this.toHide.add( this.containers );
444 // http://docs.jquery.com/Plugins/Validation/Validator/showErrors
445 showErrors: function(errors) {
447 /// Show the specified messages.
448 /// Keys have to refer to the names of elements, values are displayed for those elements, using the configured error placement.
450 /// <param name="errors" type="Object">
451 /// One or more key/value pairs of input names and messages.
455 // add items to error list and map
456 $.extend( this.errorMap, errors );
458 for ( var name in errors ) {
459 this.errorList.push({
460 message: errors[name],
461 element: this.findByName(name)[0]
464 // remove items from success list
465 this.successList = $.grep( this.successList, function(element) {
466 return !(element.name in errors);
469 this.settings.showErrors
470 ? this.settings.showErrors.call( this, this.errorMap, this.errorList )
471 : this.defaultShowErrors();
474 // http://docs.jquery.com/Plugins/Validation/Validator/resetForm
475 resetForm: function() {
477 /// Resets the controlled form.
478 /// Resets input fields to their original value (requires form plugin), removes classes
479 /// indicating invalid elements and hides error messages.
482 if ( $.fn.resetForm )
483 $( this.currentForm ).resetForm();
487 this.elements().removeClass( this.settings.errorClass );
490 numberOfInvalids: function() {
492 /// Returns the number of invalid fields.
493 /// This depends on the internal validator state. It covers all fields only after
494 /// validating the complete form (on submit or via $("form").valid()). After validating
495 /// a single element, only that element is counted. Most useful in combination with the
496 /// invalidHandler-option.
498 /// <returns type="Number" />
500 return this.objectLength(this.invalid);
503 objectLength: function( obj ) {
510 hideErrors: function() {
511 this.addWrapper( this.toHide ).hide();
515 return this.size() == 0;
519 return this.errorList.length;
522 focusInvalid: function() {
523 if( this.settings.focusInvalid ) {
525 $(this.findLastActive() || this.errorList.length && this.errorList[0].element || [])
528 // manually trigger focusin event; without it, focusin handler isn't called, findLastActive won't have anything to find
531 // ignore IE throwing errors when focusing hidden elements
536 findLastActive: function() {
537 var lastActive = this.lastActive;
538 return lastActive && $.grep(this.errorList, function(n) {
539 return n.element.name == lastActive.name;
540 }).length == 1 && lastActive;
543 elements: function() {
544 var validator = this,
547 // select all valid inputs inside the form (no submit or reset buttons)
548 // workaround $Query([]).add until http://dev.jquery.com/ticket/2114 is solved
549 return $([]).add(this.currentForm.elements)
551 .not(":submit, :reset, :image, [disabled]")
552 .not( this.settings.ignore )
554 !this.name && validator.settings.debug && window.console && console.error( "%o has no name assigned", this);
556 // select only the first element for each name, and only those with rules specified
557 if ( this.name in rulesCache || !validator.objectLength($(this).rules()) )
560 rulesCache[this.name] = true;
565 clean: function( selector ) {
566 return $( selector )[0];
570 return $( this.settings.errorElement + "." + this.settings.errorClass, this.errorContext );
574 this.successList = [];
579 this.currentElements = $([]);
582 prepareForm: function() {
584 this.toHide = this.errors().add( this.containers );
587 prepareElement: function( element ) {
589 this.toHide = this.errorsFor(element);
592 check: function( element ) {
593 element = this.clean( element );
595 // if radio/checkbox, validate first element in group instead
596 if (this.checkable(element)) {
597 element = this.findByName(element.name).not(this.settings.ignore)[0];
600 var rules = $(element).rules();
601 var dependencyMismatch = false;
602 for (var method in rules) {
603 var rule = { method: method, parameters: rules[method] };
605 var result = $.validator.methods[method].call( this, element.value.replace(/\r/g, ""), element, rule.parameters );
607 // if a method indicates that the field is optional and therefore valid,
608 // don't mark it as valid when there are no other rules
609 if ( result == "dependency-mismatch" ) {
610 dependencyMismatch = true;
613 dependencyMismatch = false;
615 if ( result == "pending" ) {
616 this.toHide = this.toHide.not( this.errorsFor(element) );
621 this.formatAndAdd( element, rule );
625 this.settings.debug && window.console && console.log("exception occured when checking element " + element.id
626 + ", check the '" + rule.method + "' method", e);
630 if (dependencyMismatch)
632 if ( this.objectLength(rules) )
633 this.successList.push(element);
637 // return the custom message for the given element and validation method
638 // specified in the element's "messages" metadata
639 customMetaMessage: function(element, method) {
643 var meta = this.settings.meta
644 ? $(element).metadata()[this.settings.meta]
645 : $(element).metadata();
647 return meta && meta.messages && meta.messages[method];
650 // return the custom message for the given element name and validation method
651 customMessage: function( name, method ) {
652 var m = this.settings.messages[name];
653 return m && (m.constructor == String
658 // return the first defined argument, allowing empty strings
659 findDefined: function() {
660 for(var i = 0; i < arguments.length; i++) {
661 if (arguments[i] !== undefined)
667 defaultMessage: function( element, method) {
668 return this.findDefined(
669 this.customMessage( element.name, method ),
670 this.customMetaMessage( element, method ),
671 // title is never undefined, so handle empty string as undefined
672 !this.settings.ignoreTitle && element.title || undefined,
673 $.validator.messages[method],
674 "<strong>Warning: No message defined for " + element.name + "</strong>"
678 formatAndAdd: function( element, rule ) {
679 var message = this.defaultMessage( element, rule.method ),
680 theregex = /\$?\{(\d+)\}/g;
681 if ( typeof message == "function" ) {
682 message = message.call(this, rule.parameters, element);
683 } else if (theregex.test(message)) {
684 message = jQuery.format(message.replace(theregex, '{$1}'), rule.parameters);
686 this.errorList.push({
691 this.errorMap[element.name] = message;
692 this.submitted[element.name] = message;
695 addWrapper: function(toToggle) {
696 if ( this.settings.wrapper )
697 toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) );
701 defaultShowErrors: function() {
702 for ( var i = 0; this.errorList[i]; i++ ) {
703 var error = this.errorList[i];
704 this.settings.highlight && this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass );
705 this.showLabel( error.element, error.message );
707 if( this.errorList.length ) {
708 this.toShow = this.toShow.add( this.containers );
710 if (this.settings.success) {
711 for ( var i = 0; this.successList[i]; i++ ) {
712 this.showLabel( this.successList[i] );
715 if (this.settings.unhighlight) {
716 for ( var i = 0, elements = this.validElements(); elements[i]; i++ ) {
717 this.settings.unhighlight.call( this, elements[i], this.settings.errorClass, this.settings.validClass );
720 this.toHide = this.toHide.not( this.toShow );
722 this.addWrapper( this.toShow ).show();
725 validElements: function() {
726 return this.currentElements.not(this.invalidElements());
729 invalidElements: function() {
730 return $(this.errorList).map(function() {
735 showLabel: function(element, message) {
736 var label = this.errorsFor( element );
737 if ( label.length ) {
738 // refresh error/success class
739 label.removeClass().addClass( this.settings.errorClass );
741 // check if we have a generated label, replace the message then
742 label.attr("generated") && label.html(message);
745 label = $("<" + this.settings.errorElement + "/>")
746 .attr({"for": this.idOrName(element), generated: true})
747 .addClass(this.settings.errorClass)
748 .html(message || "");
749 if ( this.settings.wrapper ) {
750 // make sure the element is visible, even in IE
751 // actually showing the wrapped element is handled elsewhere
752 label = label.hide().show().wrap("<" + this.settings.wrapper + "/>").parent();
754 if ( !this.labelContainer.append(label).length )
755 this.settings.errorPlacement
756 ? this.settings.errorPlacement(label, $(element) )
757 : label.insertAfter(element);
759 if ( !message && this.settings.success ) {
761 typeof this.settings.success == "string"
762 ? label.addClass( this.settings.success )
763 : this.settings.success( label );
765 this.toShow = this.toShow.add(label);
768 errorsFor: function(element) {
769 var name = this.idOrName(element);
770 return this.errors().filter(function() {
771 return $(this).attr('for') == name;
775 idOrName: function(element) {
776 return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name);
779 checkable: function( element ) {
780 return /radio|checkbox/i.test(element.type);
783 findByName: function( name ) {
784 // select by name and filter by form for performance over form.find("[name=...]")
785 var form = this.currentForm;
786 return $(document.getElementsByName(name)).map(function(index, element) {
787 return element.form == form && element.name == name && element || null;
791 getLength: function(value, element) {
792 switch( element.nodeName.toLowerCase() ) {
794 return $("option:selected", element).length;
796 if( this.checkable( element) )
797 return this.findByName(element.name).filter(':checked').length;
802 depend: function(param, element) {
803 return this.dependTypes[typeof param]
804 ? this.dependTypes[typeof param](param, element)
809 "boolean": function(param, element) {
812 "string": function(param, element) {
813 return !!$(param, element.form).length;
815 "function": function(param, element) {
816 return param(element);
820 optional: function(element) {
821 return !$.validator.methods.required.call(this, $.trim(element.value), element) && "dependency-mismatch";
824 startRequest: function(element) {
825 if (!this.pending[element.name]) {
826 this.pendingRequest++;
827 this.pending[element.name] = true;
831 stopRequest: function(element, valid) {
832 this.pendingRequest--;
833 // sometimes synchronization fails, make sure pendingRequest is never < 0
834 if (this.pendingRequest < 0)
835 this.pendingRequest = 0;
836 delete this.pending[element.name];
837 if ( valid && this.pendingRequest == 0 && this.formSubmitted && this.form() ) {
838 $(this.currentForm).submit();
839 this.formSubmitted = false;
840 } else if (!valid && this.pendingRequest == 0 && this.formSubmitted) {
841 $(this.currentForm).triggerHandler("invalid-form", [this]);
842 this.formSubmitted = false;
846 previousValue: function(element) {
847 return $.data(element, "previousValue") || $.data(element, "previousValue", {
850 message: this.defaultMessage( element, "remote" )
857 required: {required: true},
858 email: {email: true},
861 dateISO: {dateISO: true},
862 dateDE: {dateDE: true},
863 number: {number: true},
864 numberDE: {numberDE: true},
865 digits: {digits: true},
866 creditcard: {creditcard: true}
869 addClassRules: function(className, rules) {
871 /// Add a compound class method - useful to refactor common combinations of rules into a single
874 /// <param name="name" type="String">
875 /// The name of the class rule to add
877 /// <param name="rules" type="Options">
878 /// The compound rules
881 className.constructor == String ?
882 this.classRuleSettings[className] = rules :
883 $.extend(this.classRuleSettings, className);
886 classRules: function(element) {
888 var classes = $(element).attr('class');
889 classes && $.each(classes.split(' '), function() {
890 if (this in $.validator.classRuleSettings) {
891 $.extend(rules, $.validator.classRuleSettings[this]);
897 attributeRules: function(element) {
899 var $element = $(element);
901 for (var method in $.validator.methods) {
902 var value = $element.attr(method);
904 rules[method] = value;
908 // maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs
909 if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) {
910 delete rules.maxlength;
916 metadataRules: function(element) {
917 if (!$.metadata) return {};
919 var meta = $.data(element.form, 'validator').settings.meta;
921 $(element).metadata()[meta] :
922 $(element).metadata();
925 staticRules: function(element) {
927 var validator = $.data(element.form, 'validator');
928 if (validator.settings.rules) {
929 rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {};
934 normalizeRules: function(rules, element) {
935 // handle dependency check
936 $.each(rules, function(prop, val) {
937 // ignore rule when param is explicitly false, eg. required:false
942 if (val.param || val.depends) {
944 switch (typeof val.depends) {
946 keepRule = !!$(val.depends, element.form).length;
949 keepRule = val.depends.call(element, element);
953 rules[prop] = val.param !== undefined ? val.param : true;
960 // evaluate parameters
961 $.each(rules, function(rule, parameter) {
962 rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter;
965 // clean number parameters
966 $.each(['minlength', 'maxlength', 'min', 'max'], function() {
968 rules[this] = Number(rules[this]);
971 $.each(['rangelength', 'range'], function() {
973 rules[this] = [Number(rules[this][0]), Number(rules[this][1])];
977 if ($.validator.autoCreateRanges) {
978 // auto-create ranges
979 if (rules.min && rules.max) {
980 rules.range = [rules.min, rules.max];
984 if (rules.minlength && rules.maxlength) {
985 rules.rangelength = [rules.minlength, rules.maxlength];
986 delete rules.minlength;
987 delete rules.maxlength;
991 // To support custom messages in metadata ignore rule methods titled "messages"
992 if (rules.messages) {
993 delete rules.messages;
999 // Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
1000 normalizeRule: function(data) {
1001 if( typeof data == "string" ) {
1002 var transformed = {};
1003 $.each(data.split(/\s/), function() {
1004 transformed[this] = true;
1011 // http://docs.jquery.com/Plugins/Validation/Validator/addMethod
1012 addMethod: function(name, method, message) {
1014 /// Add a custom validation method. It must consist of a name (must be a legal javascript
1015 /// identifier), a javascript based function and a default string message.
1017 /// <param name="name" type="String">
1018 /// The name of the method, used to identify and referencing it, must be a valid javascript
1021 /// <param name="method" type="Function">
1022 /// The actual method implementation, returning true if an element is valid
1024 /// <param name="message" type="String" optional="true">
1025 /// (Optional) The default message to display for this method. Can be a function created by
1026 /// jQuery.validator.format(value). When undefined, an already existing message is used
1027 /// (handy for localization), otherwise the field-specific messages have to be defined.
1030 $.validator.methods[name] = method;
1031 $.validator.messages[name] = message != undefined ? message : $.validator.messages[name];
1032 if (method.length < 3) {
1033 $.validator.addClassRules(name, $.validator.normalizeRule(name));
1039 // http://docs.jquery.com/Plugins/Validation/Methods/required
1040 required: function(value, element, param) {
1041 // check if dependency is met
1042 if ( !this.depend(param, element) )
1043 return "dependency-mismatch";
1044 switch( element.nodeName.toLowerCase() ) {
1046 // could be an array for select-multiple or a string, both are fine this way
1047 var val = $(element).val();
1048 return val && val.length > 0;
1050 if ( this.checkable(element) )
1051 return this.getLength(value, element) > 0;
1053 return $.trim(value).length > 0;
1057 // http://docs.jquery.com/Plugins/Validation/Methods/remote
1058 remote: function(value, element, param) {
1059 if ( this.optional(element) )
1060 return "dependency-mismatch";
1062 var previous = this.previousValue(element);
1063 if (!this.settings.messages[element.name] )
1064 this.settings.messages[element.name] = {};
1065 previous.originalMessage = this.settings.messages[element.name].remote;
1066 this.settings.messages[element.name].remote = previous.message;
1068 param = typeof param == "string" && {url:param} || param;
1070 if ( this.pending[element.name] ) {
1073 if ( previous.old === value ) {
1074 return previous.valid;
1077 previous.old = value;
1078 var validator = this;
1079 this.startRequest(element);
1081 data[element.name] = value;
1082 $.ajax($.extend(true, {
1085 port: "validate" + element.name,
1088 success: function(response) {
1089 validator.settings.messages[element.name].remote = previous.originalMessage;
1090 var valid = response === true;
1092 var submitted = validator.formSubmitted;
1093 validator.prepareElement(element);
1094 validator.formSubmitted = submitted;
1095 validator.successList.push(element);
1096 validator.showErrors();
1099 var message = response || validator.defaultMessage(element, "remote");
1100 errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message;
1101 validator.showErrors(errors);
1103 previous.valid = valid;
1104 validator.stopRequest(element, valid);
1110 // http://docs.jquery.com/Plugins/Validation/Methods/minlength
1111 minlength: function(value, element, param) {
1112 return this.optional(element) || this.getLength($.trim(value), element) >= param;
1115 // http://docs.jquery.com/Plugins/Validation/Methods/maxlength
1116 maxlength: function(value, element, param) {
1117 return this.optional(element) || this.getLength($.trim(value), element) <= param;
1120 // http://docs.jquery.com/Plugins/Validation/Methods/rangelength
1121 rangelength: function(value, element, param) {
1122 var length = this.getLength($.trim(value), element);
1123 return this.optional(element) || ( length >= param[0] && length <= param[1] );
1126 // http://docs.jquery.com/Plugins/Validation/Methods/min
1127 min: function( value, element, param ) {
1128 return this.optional(element) || value >= param;
1131 // http://docs.jquery.com/Plugins/Validation/Methods/max
1132 max: function( value, element, param ) {
1133 return this.optional(element) || value <= param;
1136 // http://docs.jquery.com/Plugins/Validation/Methods/range
1137 range: function( value, element, param ) {
1138 return this.optional(element) || ( value >= param[0] && value <= param[1] );
1141 // http://docs.jquery.com/Plugins/Validation/Methods/email
1142 email: function(value, element) {
1143 // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
1144 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);
1147 // http://docs.jquery.com/Plugins/Validation/Methods/url
1148 url: function(value, element) {
1149 // contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/
1150 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);
1153 // http://docs.jquery.com/Plugins/Validation/Methods/date
1154 date: function(value, element) {
1155 return this.optional(element) || !/Invalid|NaN/.test(new Date(value));
1158 // http://docs.jquery.com/Plugins/Validation/Methods/dateISO
1159 dateISO: function(value, element) {
1160 return this.optional(element) || /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(value);
1163 // http://docs.jquery.com/Plugins/Validation/Methods/number
1164 number: function(value, element) {
1165 return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value);
1168 // http://docs.jquery.com/Plugins/Validation/Methods/digits
1169 digits: function(value, element) {
1170 return this.optional(element) || /^\d+$/.test(value);
1173 // http://docs.jquery.com/Plugins/Validation/Methods/creditcard
1174 // based on http://en.wikipedia.org/wiki/Luhn
1175 creditcard: function(value, element) {
1176 if ( this.optional(element) )
1177 return "dependency-mismatch";
1178 // accept only digits and dashes
1179 if (/[^0-9-]+/.test(value))
1185 value = value.replace(/\D/g, "");
1187 for (var n = value.length - 1; n >= 0; n--) {
1188 var cDigit = value.charAt(n);
1189 var nDigit = parseInt(cDigit, 10);
1191 if ((nDigit *= 2) > 9)
1198 return (nCheck % 10) == 0;
1201 // http://docs.jquery.com/Plugins/Validation/Methods/accept
1202 accept: function(value, element, param) {
1203 param = typeof param == "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif";
1204 return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i"));
1207 // http://docs.jquery.com/Plugins/Validation/Methods/equalTo
1208 equalTo: function(value, element, param) {
1209 // bind to the blur event of the target in order to revalidate whenever the target field is updated
1210 // TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
1211 var target = $(param).unbind(".validate-equalTo").bind("blur.validate-equalTo", function() {
1214 return value == target.val();
1221 // deprecated, use $.validator.format instead
1222 $.format = $.validator.format;
1227 // usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
1228 // if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()
1230 var pendingRequests = {};
1231 // Use a prefilter if available (1.5+)
1232 if ( $.ajaxPrefilter ) {
1233 $.ajaxPrefilter(function(settings, _, xhr) {
1234 var port = settings.port;
1235 if (settings.mode == "abort") {
1236 if ( pendingRequests[port] ) {
1237 pendingRequests[port].abort();
1238 } pendingRequests[port] = xhr;
1244 $.ajax = function(settings) {
1245 var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
1246 port = ( "port" in settings ? settings : $.ajaxSettings ).port;
1247 if (mode == "abort") {
1248 if ( pendingRequests[port] ) {
1249 pendingRequests[port].abort();
1252 return (pendingRequests[port] = ajax.apply(this, arguments));
1254 return ajax.apply(this, arguments);
1259 // provides cross-browser focusin and focusout events
1260 // IE has native support, in other browsers, use event caputuring (neither bubbles)
1262 // provides delegate(type: String, delegate: Selector, handler: Callback) plugin for easier event delegation
1263 // handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target
1265 // only implement if not provided by jQuery core (since 1.4)
1266 // TODO verify if jQuery 1.4's implementation is compatible with older jQuery special-event APIs
1267 if (!jQuery.event.special.focusin && !jQuery.event.special.focusout && document.addEventListener) {
1271 }, function( original, fix ){
1272 $.event.special[fix] = {
1274 this.addEventListener( original, handler, true );
1276 teardown:function() {
1277 this.removeEventListener( original, handler, true );
1279 handler: function(e) {
1280 arguments[0] = $.event.fix(e);
1281 arguments[0].type = fix;
1282 return $.event.handle.apply(this, arguments);
1285 function handler(e) {
1288 return $.event.handle.call(this, e);
1293 validateDelegate: function(delegate, type, handler) {
1294 return this.bind(type, function(event) {
1295 var target = $(event.target);
1296 if (target.is(delegate)) {
1297 return handler.apply(target, arguments);