Updated coding style

This commit is contained in:
Robert
2013-01-29 15:07:40 +02:00
committed by Jörn Zaefferer
parent b5cd04e327
commit 0d394a7418

314
jquery.validate.js vendored
View File

@@ -16,33 +16,33 @@ $.extend($.fn, {
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" );
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');
var validator = $.data( this[0], "validator" );
if ( validator ) {
return validator;
}
// Add novalidate tag if HTML5.
this.attr('novalidate', 'novalidate');
this.attr( "novalidate", "novalidate" );
validator = new $.validator( options, this[0] );
$.data(this[0], 'validator', validator);
$.data( this[0], "validator", validator );
if ( validator.settings.onsubmit ) {
this.validateDelegate( ":submit", "click", function(ev) {
this.validateDelegate( ":submit", "click", function( event ) {
if ( validator.settings.submitHandler ) {
validator.submitButton = ev.target;
validator.submitButton = event.target;
}
// allow suppressing validation by adding a cancel class to the submit button
if ( $(ev.target).hasClass('cancel') ) {
if ( $(event.target).hasClass("cancel") ) {
validator.cancelSubmit = true;
}
});
@@ -56,12 +56,12 @@ $.extend($.fn, {
function handle() {
var hidden;
if ( validator.settings.submitHandler ) {
if (validator.submitButton) {
if ( validator.submitButton ) {
// insert a hidden input as a replacement for the missing submit button
hidden = $("<input type='hidden'/>").attr("name", validator.submitButton.name).val(validator.submitButton.value).appendTo(validator.currentForm);
}
validator.settings.submitHandler.call( validator, validator.currentForm, event );
if (validator.submitButton) {
if ( validator.submitButton ) {
// and clean up afterwards; thanks to no-block-scope, hidden can be referenced
hidden.remove();
}
@@ -92,7 +92,7 @@ $.extend($.fn, {
},
// http://docs.jquery.com/Plugins/Validation/valid
valid: function() {
if ( $(this[0]).is('form')) {
if ( $(this[0]).is("form")) {
return this.validate().form();
} else {
var valid = true;
@@ -104,38 +104,38 @@ $.extend($.fn, {
}
},
// attributes: space seperated list of attributes to retrieve and remove
removeAttrs: function(attributes) {
removeAttrs: function( attributes ) {
var result = {},
$element = this;
$.each(attributes.split(/\s/), function(index, value) {
$.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) {
rules: function( command, argument ) {
var element = this[0];
if (command) {
var settings = $.data(element.form, 'validator').settings;
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) {
if ( argument.messages ) {
settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages );
}
break;
case "remove":
if (!argument) {
if ( !argument ) {
delete staticRules[element.name];
return existingRules;
}
var filtered = {};
$.each(argument.split(/\s/), function(index, method) {
$.each(argument.split(/\s/), function( index, method ) {
filtered[method] = existingRules[method];
delete existingRules[method];
});
@@ -153,7 +153,7 @@ $.extend($.fn, {
), element);
// make sure required is at front
if (data.required) {
if ( data.required ) {
var param = data.required;
delete data.required;
data = $.extend({required: param}, data);
@@ -166,11 +166,11 @@ $.extend($.fn, {
// Custom selectors
$.extend($.expr[":"], {
// http://docs.jquery.com/Plugins/Validation/blank
blank: function(a) {return !$.trim("" + a.value);},
blank: function( a ) { return !$.trim("" + a.value); },
// http://docs.jquery.com/Plugins/Validation/filled
filled: function(a) {return !!$.trim("" + a.value);},
filled: function( a ) { return !!$.trim("" + a.value); },
// http://docs.jquery.com/Plugins/Validation/unchecked
unchecked: function(a) {return !a.checked;}
unchecked: function( a ) { return !a.checked; }
});
// constructor for validator
@@ -180,7 +180,7 @@ $.validator = function( options, form ) {
this.init();
};
$.validator.format = function(source, params) {
$.validator.format = function( source, params ) {
if ( arguments.length === 1 ) {
return function() {
var args = $.makeArray(arguments);
@@ -194,8 +194,8 @@ $.validator.format = function(source, params) {
if ( params.constructor !== Array ) {
params = [ params ];
}
$.each(params, function(i, n) {
source = source.replace(new RegExp("\\{" + i + "\\}", "g"), function() {
$.each(params, function( i, n ) {
source = source.replace( new RegExp("\\{" + i + "\\}", "g"), function() {
return n;
});
});
@@ -212,12 +212,12 @@ $.extend($.validator, {
validClass: "valid",
errorElement: "label",
focusInvalid: true,
errorContainer: $( [] ),
errorLabelContainer: $( [] ),
errorContainer: $([]),
errorLabelContainer: $([]),
onsubmit: true,
ignore: ":hidden",
ignoreTitle: false,
onfocusin: function(element, event) {
onfocusin: function( element, event ) {
this.lastActive = element;
// hide error label and remove error class on focus if enabled
@@ -228,37 +228,37 @@ $.extend($.validator, {
this.addWrapper(this.errorsFor(element)).hide();
}
},
onfocusout: function(element, event) {
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) === '' ) {
onkeyup: function( element, event ) {
if ( event.which === 9 && this.elementValue(element) === "" ) {
return;
} else if ( element.name in this.submitted || element === this.lastElement ) {
this.element(element);
}
},
onclick: function(element, event) {
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) {
else if ( element.parentNode.name in this.submitted ) {
this.element(element.parentNode);
}
},
highlight: function(element, errorClass, validClass) {
if (element.type === 'radio') {
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') {
unhighlight: function( element, errorClass, validClass ) {
if ( element.type === "radio" ) {
this.findByName(element.name).removeClass(errorClass).addClass(validClass);
} else {
$(element).removeClass(errorClass).addClass(validClass);
@@ -267,7 +267,7 @@ $.extend($.validator, {
},
// http://docs.jquery.com/Plugins/Validation/Validator/setDefaults
setDefaults: function(settings) {
setDefaults: function( settings ) {
$.extend( $.validator.defaults, settings );
},
@@ -306,23 +306,23 @@ $.extend($.validator, {
this.reset();
var groups = (this.groups = {});
$.each(this.settings.groups, function(key, value) {
if (typeof value === "string") {
$.each(this.settings.groups, function( key, value ) {
if ( typeof value === "string" ) {
value = value.split(/\s/);
}
$.each(value, function(index, name) {
$.each(value, function( index, name ) {
groups[name] = key;
});
});
var rules = this.settings.rules;
$.each(rules, function(key, value) {
$.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]) {
if ( validator.settings[eventType] ) {
validator.settings[eventType].call(validator, this[0], event);
}
}
@@ -335,7 +335,7 @@ $.extend($.validator, {
"focusin focusout keyup", delegate)
.validateDelegate("[type='radio'], [type='checkbox'], select, option", "click", delegate);
if (this.settings.invalidHandler) {
if ( this.settings.invalidHandler ) {
$(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler);
}
},
@@ -345,7 +345,7 @@ $.extend($.validator, {
this.checkForm();
$.extend(this.submitted, this.errorMap);
this.invalid = $.extend({}, this.errorMap);
if (!this.valid()) {
if ( !this.valid() ) {
$(this.currentForm).triggerHandler("invalid-form", [this]);
}
this.showErrors();
@@ -367,7 +367,7 @@ $.extend($.validator, {
this.prepareElement( element );
this.currentElements = $(element);
var result = this.check( element ) !== false;
if (result) {
if ( result ) {
delete this.invalid[element.name];
} else {
this.invalid[element.name] = true;
@@ -381,8 +381,8 @@ $.extend($.validator, {
},
// http://docs.jquery.com/Plugins/Validation/Validator/showErrors
showErrors: function(errors) {
if(errors) {
showErrors: function( errors ) {
if ( errors ) {
// add items to error list and map
$.extend( this.errorMap, errors );
this.errorList = [];
@@ -393,11 +393,11 @@ $.extend($.validator, {
});
}
// remove items from success list
this.successList = $.grep( this.successList, function(element) {
this.successList = $.grep( this.successList, function( element ) {
return !(element.name in errors);
});
}
if (this.settings.showErrors) {
if ( this.settings.showErrors ) {
this.settings.showErrors.call( this, this.errorMap, this.errorList );
} else {
this.defaultShowErrors();
@@ -407,7 +407,7 @@ $.extend($.validator, {
// http://docs.jquery.com/Plugins/Validation/Validator/resetForm
resetForm: function() {
if ( $.fn.resetForm ) {
$( this.currentForm ).resetForm();
$(this.currentForm).resetForm();
}
this.submitted = {};
this.lastElement = null;
@@ -441,7 +441,7 @@ $.extend($.validator, {
},
focusInvalid: function() {
if( this.settings.focusInvalid ) {
if ( this.settings.focusInvalid ) {
try {
$(this.findLastActive() || this.errorList.length && this.errorList[0].element || [])
.filter(":visible")
@@ -456,7 +456,7 @@ $.extend($.validator, {
findLastActive: function() {
var lastActive = this.lastActive;
return lastActive && $.grep(this.errorList, function(n) {
return lastActive && $.grep(this.errorList, function( n ) {
return n.element.name === lastActive.name;
}).length === 1 && lastActive;
},
@@ -486,12 +486,12 @@ $.extend($.validator, {
},
clean: function( selector ) {
return $( selector )[0];
return $(selector)[0];
},
errors: function() {
var errorClass = this.settings.errorClass.replace(' ', '.');
return $( this.settings.errorElement + "." + errorClass, this.errorContext );
var errorClass = this.settings.errorClass.replace(" ", ".");
return $(this.settings.errorElement + "." + errorClass, this.errorContext);
},
reset: function() {
@@ -514,14 +514,14 @@ $.extend($.validator, {
},
elementValue: function( element ) {
var type = $(element).attr('type'),
var type = $(element).attr("type"),
val = $(element).val();
if ( type === 'radio' || type === 'checkbox' ) {
return $('input[name="' + $(element).attr('name') + '"]:checked').val();
if ( type === "radio" || type === "checkbox" ) {
return $("input[name='" + $(element).attr("name") + "']:checked").val();
}
if ( typeof val === 'string' ) {
if ( typeof val === "string" ) {
return val.replace(/\r/g, "");
}
return val;
@@ -554,18 +554,18 @@ $.extend($.validator, {
return;
}
if( !result ) {
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);
console.log( "Exception occured when checking element " + element.id + ", check the '" + rule.method + "' method.", e );
}
throw e;
}
}
if (dependencyMismatch) {
if ( dependencyMismatch ) {
return;
}
if ( this.objectLength(rules) ) {
@@ -576,8 +576,8 @@ $.extend($.validator, {
// 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()));
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
@@ -589,14 +589,14 @@ $.extend($.validator, {
// return the first defined argument, allowing empty strings
findDefined: function() {
for(var i = 0; i < arguments.length; i++) {
if (arguments[i] !== undefined) {
if ( arguments[i] !== undefined ) {
return arguments[i];
}
}
return undefined;
},
defaultMessage: function( element, method) {
defaultMessage: function( element, method ) {
return this.findDefined(
this.customMessage( element.name, method ),
this.customDataMessage( element, method ),
@@ -613,7 +613,7 @@ $.extend($.validator, {
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);
message = $.validator.format(message.replace(theregex, "{$1}"), rule.parameters);
}
this.errorList.push({
message: message,
@@ -624,7 +624,7 @@ $.extend($.validator, {
this.submitted[element.name] = message;
},
addWrapper: function(toToggle) {
addWrapper: function( toToggle ) {
if ( this.settings.wrapper ) {
toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) );
}
@@ -640,15 +640,15 @@ $.extend($.validator, {
}
this.showLabel( error.element, error.message );
}
if( this.errorList.length ) {
if ( this.errorList.length ) {
this.toShow = this.toShow.add( this.containers );
}
if (this.settings.success) {
if ( this.settings.success ) {
for ( i = 0; this.successList[i]; i++ ) {
this.showLabel( this.successList[i] );
}
}
if (this.settings.unhighlight) {
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 );
}
@@ -668,7 +668,7 @@ $.extend($.validator, {
});
},
showLabel: function(element, message) {
showLabel: function( element, message ) {
var label = this.errorsFor( element );
if ( label.length ) {
// refresh error/success class
@@ -708,20 +708,20 @@ $.extend($.validator, {
this.toShow = this.toShow.add(label);
},
errorsFor: function(element) {
errorsFor: function( element ) {
var name = this.idOrName(element);
return this.errors().filter(function() {
return $(this).attr('for') === name;
return $(this).attr("for") === name;
});
},
idOrName: function(element) {
idOrName: function( element ) {
return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name);
},
validationTargetFor: function(element) {
validationTargetFor: function( element ) {
// if radio/checkbox, validate first element in group instead
if (this.checkable(element)) {
if ( this.checkable(element) ) {
element = this.findByName( element.name ).not(this.settings.ignore)[0];
}
return element;
@@ -732,53 +732,53 @@ $.extend($.validator, {
},
findByName: function( name ) {
return $(this.currentForm).find('[name="' + name + '"]');
return $(this.currentForm).find("[name='" + name + "']");
},
getLength: function(value, element) {
getLength: function( value, element ) {
switch( element.nodeName.toLowerCase() ) {
case 'select':
case "select":
return $("option:selected", element).length;
case 'input':
if( this.checkable( element) ) {
return this.findByName(element.name).filter(':checked').length;
case "input":
if ( this.checkable( element) ) {
return this.findByName(element.name).filter(":checked").length;
}
}
return value.length;
},
depend: function(param, element) {
depend: function( param, element ) {
return this.dependTypes[typeof param] ? this.dependTypes[typeof param](param, element) : true;
},
dependTypes: {
"boolean": function(param, element) {
"boolean": function( param, element ) {
return param;
},
"string": function(param, element) {
"string": function( param, element ) {
return !!$(param, element.form).length;
},
"function": function(param, element) {
"function": function( param, element ) {
return param(element);
}
},
optional: function(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]) {
startRequest: function( element ) {
if ( !this.pending[element.name] ) {
this.pendingRequest++;
this.pending[element.name] = true;
}
},
stopRequest: function(element, valid) {
stopRequest: function( element, valid ) {
this.pendingRequest--;
// sometimes synchronization fails, make sure pendingRequest is never < 0
if (this.pendingRequest < 0) {
if ( this.pendingRequest < 0 ) {
this.pendingRequest = 0;
}
delete this.pending[element.name];
@@ -791,7 +791,7 @@ $.extend($.validator, {
}
},
previousValue: function(element) {
previousValue: function( element ) {
return $.data(element, "previousValue") || $.data(element, "previousValue", {
old: null,
valid: true,
@@ -812,7 +812,7 @@ $.extend($.validator, {
creditcard: {creditcard: true}
},
addClassRules: function(className, rules) {
addClassRules: function( className, rules ) {
if ( className.constructor === String ) {
this.classRuleSettings[className] = rules;
} else {
@@ -820,12 +820,12 @@ $.extend($.validator, {
}
},
classRules: function(element) {
classRules: function( element ) {
var rules = {};
var classes = $(element).attr('class');
var classes = $(element).attr("class");
if ( classes ) {
$.each(classes.split(' '), function() {
if (this in $.validator.classRuleSettings) {
$.each(classes.split(" "), function() {
if ( this in $.validator.classRuleSettings ) {
$.extend(rules, $.validator.classRuleSettings[this]);
}
});
@@ -833,7 +833,7 @@ $.extend($.validator, {
return rules;
},
attributeRules: function(element) {
attributeRules: function( element ) {
var rules = {};
var $element = $(element);
@@ -841,11 +841,11 @@ $.extend($.validator, {
var value;
// support for <input required> in both html5 and older browsers
if (method === 'required') {
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 === "") {
if ( value === "" ) {
value = true;
}
// force non-HTML5 browsers to return bool
@@ -854,51 +854,51 @@ $.extend($.validator, {
value = $element.attr(method);
}
if (value) {
if ( value ) {
rules[method] = value;
} else if ($element[0].getAttribute("type") === method) {
} 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)) {
if ( rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength) ) {
delete rules.maxlength;
}
return rules;
},
dataRules: function(element) {
dataRules: function( element ) {
var method, value,
rules = {}, $element = $(element);
for (method in $.validator.methods) {
value = $element.data('rule-' + method.toLowerCase());
if (value !== undefined) {
value = $element.data("rule-" + method.toLowerCase());
if ( value !== undefined ) {
rules[method] = value;
}
}
return rules;
},
staticRules: function(element) {
staticRules: function( element ) {
var rules = {};
var validator = $.data(element.form, 'validator');
if (validator.settings.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) {
normalizeRules: function( rules, element ) {
// handle dependency check
$.each(rules, function(prop, val) {
$.each(rules, function( prop, val ) {
// ignore rule when param is explicitly false, eg. required:false
if (val === false) {
if ( val === false ) {
delete rules[prop];
return;
}
if (val.param || val.depends) {
if ( val.param || val.depends ) {
var keepRule = true;
switch (typeof val.depends) {
case "string":
@@ -908,7 +908,7 @@ $.extend($.validator, {
keepRule = val.depends.call(element, element);
break;
}
if (keepRule) {
if ( keepRule ) {
rules[prop] = val.param !== undefined ? val.param : true;
} else {
delete rules[prop];
@@ -917,36 +917,36 @@ $.extend($.validator, {
});
// evaluate parameters
$.each(rules, function(rule, parameter) {
$.each(rules, function( rule, parameter ) {
rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter;
});
// clean number parameters
$.each(['minlength', 'maxlength', 'min', 'max'], function() {
if (rules[this]) {
$.each(["minlength", "maxlength", "min", "max"], function() {
if ( rules[this] ) {
rules[this] = Number(rules[this]);
}
});
$.each(['rangelength', 'range'], function() {
$.each(["rangelength", "range"], function() {
var parts;
if (rules[this]) {
if ($.isArray(rules[this])) {
if ( rules[this] ) {
if ( $.isArray(rules[this]) ) {
rules[this] = [Number(rules[this][0]), Number(rules[this][1])];
} else if (typeof rules[this] === 'string') {
} else if ( typeof rules[this] === "string" ) {
parts = rules[this].split(/[\s,]+/);
rules[this] = [Number(parts[0]), Number(parts[1])];
}
}
});
if ($.validator.autoCreateRanges) {
if ( $.validator.autoCreateRanges ) {
// auto-create ranges
if (rules.min && rules.max) {
if ( rules.min && rules.max ) {
rules.range = [rules.min, rules.max];
delete rules.min;
delete rules.max;
}
if (rules.minlength && rules.maxlength) {
if ( rules.minlength && rules.maxlength ) {
rules.rangelength = [rules.minlength, rules.maxlength];
delete rules.minlength;
delete rules.maxlength;
@@ -957,8 +957,8 @@ $.extend($.validator, {
},
// Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
normalizeRule: function(data) {
if( typeof data === "string" ) {
normalizeRule: function( data ) {
if ( typeof data === "string" ) {
var transformed = {};
$.each(data.split(/\s/), function() {
transformed[this] = true;
@@ -969,10 +969,10 @@ $.extend($.validator, {
},
// http://docs.jquery.com/Plugins/Validation/Validator/addMethod
addMethod: function(name, method, message) {
addMethod: function( name, method, message ) {
$.validator.methods[name] = method;
$.validator.messages[name] = message !== undefined ? message : $.validator.messages[name];
if (method.length < 3) {
if ( method.length < 3 ) {
$.validator.addClassRules(name, $.validator.normalizeRule(name));
}
},
@@ -980,7 +980,7 @@ $.extend($.validator, {
methods: {
// http://docs.jquery.com/Plugins/Validation/Methods/required
required: function(value, element, param) {
required: function( value, element, param ) {
// check if dependency is met
if ( !this.depend(param, element) ) {
return "dependency-mismatch";
@@ -997,7 +997,7 @@ $.extend($.validator, {
},
// http://docs.jquery.com/Plugins/Validation/Methods/remote
remote: function(value, element, param) {
remote: function( value, element, param ) {
if ( this.optional(element) ) {
return "dependency-mismatch";
}
@@ -1026,7 +1026,7 @@ $.extend($.validator, {
port: "validate" + element.name,
dataType: "json",
data: data,
success: function(response) {
success: function( response ) {
validator.settings.messages[element.name].remote = previous.originalMessage;
var valid = response === true || response === "true";
if ( valid ) {
@@ -1051,19 +1051,19 @@ $.extend($.validator, {
},
// http://docs.jquery.com/Plugins/Validation/Methods/minlength
minlength: function(value, element, param) {
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) {
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) {
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] );
},
@@ -1084,45 +1084,45 @@ $.extend($.validator, {
},
// http://docs.jquery.com/Plugins/Validation/Methods/email
email: function(value, element) {
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) {
url: function( value, element ) {
// contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/
return this.optional(element) || /^(https?|s?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) {
date: function( value, element ) {
return this.optional(element) || !/Invalid|NaN/.test(new Date(value).toString());
},
// http://docs.jquery.com/Plugins/Validation/Methods/dateISO
dateISO: function(value, element) {
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) {
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) {
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) {
creditcard: function( value, element ) {
if ( this.optional(element) ) {
return "dependency-mismatch";
}
// accept only spaces, digits and dashes
if (/[^0-9 \-]+/.test(value)) {
if ( /[^0-9 \-]+/.test(value) ) {
return false;
}
var nCheck = 0,
@@ -1134,8 +1134,8 @@ $.extend($.validator, {
for (var n = value.length - 1; n >= 0; n--) {
var cDigit = value.charAt(n);
nDigit = parseInt(cDigit, 10);
if (bEven) {
if ((nDigit *= 2) > 9) {
if ( bEven ) {
if ( (nDigit *= 2) > 9 ) {
nDigit -= 9;
}
}
@@ -1147,11 +1147,11 @@ $.extend($.validator, {
},
// http://docs.jquery.com/Plugins/Validation/Methods/equalTo
equalTo: function(value, element, param) {
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) {
if ( this.settings.onfocusout ) {
target.unbind(".validate-equalTo").bind("blur.validate-equalTo", function() {
$(element).valid();
});
@@ -1175,9 +1175,9 @@ $.format = $.validator.format;
var pendingRequests = {};
// Use a prefilter if available (1.5+)
if ( $.ajaxPrefilter ) {
$.ajaxPrefilter(function(settings, _, xhr) {
$.ajaxPrefilter(function( settings, _, xhr ) {
var port = settings.port;
if (settings.mode === "abort") {
if ( settings.mode === "abort" ) {
if ( pendingRequests[port] ) {
pendingRequests[port].abort();
}
@@ -1187,10 +1187,10 @@ $.format = $.validator.format;
} else {
// Proxy ajax
var ajax = $.ajax;
$.ajax = function(settings) {
$.ajax = function( settings ) {
var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
port = ( "port" in settings ? settings : $.ajaxSettings ).port;
if (mode === "abort") {
if ( mode === "abort" ) {
if ( pendingRequests[port] ) {
pendingRequests[port].abort();
}
@@ -1205,10 +1205,10 @@ $.format = $.validator.format;
// handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target
(function($) {
$.extend($.fn, {
validateDelegate: function(delegate, type, handler) {
return this.bind(type, function(event) {
validateDelegate: function( delegate, type, handler ) {
return this.bind(type, function( event ) {
var target = $(event.target);
if (target.is(delegate)) {
if ( target.is(delegate) ) {
return handler.apply(target, arguments);
}
});