: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
return lastActive && $.grep(this.errorList, function( n ) {
return n.element.name === lastActive.name;
}).length === 1 && lastActive;
// select all valid inputs inside the form (no submit or reset buttons)
return $(this.currentForm)
.find("input, select, textarea")
.not(":submit, :reset, :image, [disabled]")
.not( this.settings.ignore )
if ( !this.name && validator.settings.debug && window.console ) {
console.error( "%o has no name assigned", this);
// select only the first element for each name, and only those with rules specified
if ( this.name in rulesCache || !validator.objectLength($(this).rules()) ) {
rulesCache[this.name] = true;
clean: function( selector ) {
var errorClass = this.settings.errorClass.split(" ").join(".");
return $(this.settings.errorElement + "." + errorClass, this.errorContext);
this.currentElements = $([]);
prepareForm: function() {
this.toHide = this.errors().add( this.containers );
prepareElement: function( element ) {
this.toHide = this.errorsFor(element);
elementValue: function( element ) {
type = $element.attr("type");
if ( type === "radio" || type === "checkbox" ) {
return $("input[name='" + $element.attr("name") + "']:checked").val();
if ( typeof val === "string" ) {
return val.replace(/\r/g, "");
check: function( element ) {
element = this.validationTargetFor( this.clean( element ) );
var rules = $(element).rules(),
rulesCount = $.map( rules, function(n, i) {
dependencyMismatch = false,
val = this.elementValue(element),
rule = { method: method, parameters: rules[method] };
result = $.validator.methods[method].call( this, val, element, rule.parameters );
// if a method indicates that the field is optional and therefore valid,
// don't mark it as valid when there are no other rules
if ( result === "dependency-mismatch" && rulesCount === 1 ) {
dependencyMismatch = true;
dependencyMismatch = false;
if ( result === "pending" ) {
this.toHide = this.toHide.not( this.errorsFor(element) );
this.formatAndAdd( element, rule );
if ( this.settings.debug && window.console ) {
console.log( "Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.", e );
if ( dependencyMismatch ) {
if ( this.objectLength(rules) ) {
this.successList.push(element);
// return the custom message for the given element and validation method
// specified in the element's HTML5 data attribute
// return the generic message if present and no method specific message is present
customDataMessage: function( element, method ) {
return $( element ).data( "msg" + method[ 0 ].toUpperCase() +
method.substring( 1 ).toLowerCase() ) || $( element ).data("msg");
// 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 ) {
defaultMessage: function( element, method ) {
this.customMessage( element.name, method ),
this.customDataMessage( element, method ),
// title is never undefined, so handle empty string as undefined
!this.settings.ignoreTitle && element.title || undefined,
$.validator.messages[method],
"<strong>Warning: No message defined for " + element.name + "</strong>"
formatAndAdd: function( element, rule ) {
var message = this.defaultMessage( element, rule.method ),
theregex = /\$?\{(\d+)\}/g;
if ( typeof message === "function" ) {
message = message.call(this, rule.parameters, element);
} else if (theregex.test(message)) {
message = $.validator.format(message.replace(theregex, "{$1}"), rule.parameters);
this.errorMap[element.name] = message;
this.submitted[element.name] = message;
addWrapper: function( toToggle ) {
if ( this.settings.wrapper ) {
toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) );
defaultShowErrors: function() {
for ( i = 0; this.errorList[i]; i++ ) {
error = this.errorList[i];
if ( this.settings.highlight ) {
this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass );
this.showLabel( error.element, error.message );
if ( this.errorList.length ) {
this.toShow = this.toShow.add( this.containers );
if ( this.settings.success ) {
for ( i = 0; this.successList[i]; i++ ) {
this.showLabel( this.successList[i] );
if ( this.settings.unhighlight ) {
for ( i = 0, elements = this.validElements(); elements[i]; i++ ) {
this.settings.unhighlight.call( this, elements[i], this.settings.errorClass, this.settings.validClass );
this.toHide = this.toHide.not( this.toShow );
this.addWrapper( this.toShow ).show();
validElements: function() {
return this.currentElements.not(this.invalidElements());
invalidElements: function() {
return $(this.errorList).map(function() {
showLabel: function( element, message ) {
var label = this.errorsFor( element );
// refresh error/success class
label.removeClass( this.settings.validClass ).addClass( this.settings.errorClass );
// replace message on existing label
label = $("<" + this.settings.errorElement + ">")
.attr("for", this.idOrName(element))
.addClass(this.settings.errorClass)
if ( this.settings.wrapper ) {
// make sure the element is visible, even in IE
// actually showing the wrapped element is handled elsewhere
label = label.hide().show().wrap("<" + this.settings.wrapper + "/>").parent();
if ( !this.labelContainer.append(label).length ) {
if ( this.settings.errorPlacement ) {
this.settings.errorPlacement(label, $(element) );
label.insertAfter(element);
if ( !message && this.settings.success ) {
if ( typeof this.settings.success === "string" ) {
label.addClass( this.settings.success );
this.settings.success( label, element );
this.toShow = this.toShow.add(label);
errorsFor: function( element ) {
var name = this.idOrName(element);
return this.errors().filter(function() {
return $(this).attr("for") === name;
idOrName: function( element ) {
return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name);
validationTargetFor: function( element ) {
// if radio/checkbox, validate first element in group instead
if ( this.checkable(element) ) {
element = this.findByName( element.name ).not(this.settings.ignore)[0];
checkable: function( element ) {
return (/radio|checkbox/i).test(element.type);
findByName: function( name ) {
return $(this.currentForm).find("[name='" + name + "']");
getLength: function( value, element ) {
switch ( element.nodeName.toLowerCase() ) {
return $("option:selected", element).length;
if ( this.checkable( element) ) {
return this.findByName(element.name).filter(":checked").length;
depend: function( param, element ) {
return this.dependTypes[typeof param] ? this.dependTypes[typeof param](param, element) : true;
"boolean": function( param ) {
"string": function( param, element ) {
return !!$(param, element.form).length;
"function": function( param, element ) {
optional: function( element ) {
var val = this.elementValue(element);
return !$.validator.methods.required.call(this, val, element) && "dependency-mismatch";
startRequest: function( element ) {
if ( !this.pending[element.name] ) {
this.pending[element.name] = true;
stopRequest: function( element, valid ) {
// sometimes synchronization fails, make sure pendingRequest is never < 0
if ( this.pendingRequest < 0 ) {
delete this.pending[element.name];
if ( valid && this.pendingRequest === 0 && this.formSubmitted && this.form() ) {
$(this.currentForm).submit();
this.formSubmitted = false;
} else if (!valid && this.pendingRequest === 0 && this.formSubmitted) {
$(this.currentForm).triggerHandler("invalid-form", [ this ]);
this.formSubmitted = false;
previousValue: function( element ) {
return $.data(element, "previousValue") || $.data(element, "previousValue", {
message: this.defaultMessage( element, "remote" )
required: { required: true },
dateISO: { dateISO: true },
number: { number: true },
digits: { digits: true },
creditcard: { creditcard: true }
addClassRules: function( className, rules ) {
if ( className.constructor === String ) {
this.classRuleSettings[className] = rules;
$.extend(this.classRuleSettings, className);
classRules: function( element ) {
classes = $(element).attr("class");
$.each(classes.split(" "), function() {
if ( this in $.validator.classRuleSettings ) {
$.extend(rules, $.validator.classRuleSettings[this]);
attributeRules: function( element ) {
type = element.getAttribute("type"),
for (method in $.validator.methods) {
// support for <input required> in both html5 and older browsers
if ( method === "required" ) {
value = element.getAttribute(method);
// Some browsers return an empty string for the required attribute
// and non-HTML5 browsers might have required="" markup
// force non-HTML5 browsers to return bool
value = $element.attr(method);
// convert the value to a number for number inputs, and for text for backwards compability
// allows type="date" and others to be compared as strings
if ( /min|max/.test( method ) && ( type === null || /number|range|text/.test( type ) ) ) {
if ( value || value === 0 ) {
} else if ( type === method && type !== "range" ) {
// exception: the jquery validate 'range' method
// does not test for the html5 'range' type
// maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs
if ( rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength) ) {
dataRules: function( element ) {
rules = {}, $element = $( element );
for ( method in $.validator.methods ) {
value = $element.data( "rule" + method[ 0 ].toUpperCase() + method.substring( 1 ).toLowerCase() );
if ( value !== undefined ) {
staticRules: function( element ) {
validator = $.data(element.form, "validator");
if ( validator.settings.rules ) {
rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {};
normalizeRules: function( rules, element ) {
// handle dependency check
$.each(rules, function( prop, val ) {
// ignore rule when param is explicitly false, eg. required:false
if ( val.param || val.depends ) {
switch (typeof val.depends) {
keepRule = !!$(val.depends, element.form).length;
keepRule = val.depends.call(element, element);
rules[prop] = val.param !== undefined ? val.param : true;
$.each(rules, function( rule, parameter ) {
rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter;
// clean number parameters
$.each([ "minlength", "maxlength" ], function() {
rules[this] = Number(rules[this]);
$.each([ "rangelength", "range" ], function() {
if ( $.isArray(rules[this]) ) {
rules[this] = [ Number(rules[this][0]), Number(rules[this][1]) ];
} else if ( typeof rules[this] === "string" ) {
parts = rules[this].split(/[\s,]+/);
rules[this] = [ Number(parts[0]), Number(parts[1]) ];
if ( $.validator.autoCreateRanges ) {