jquery.validate Range Method Patch

Posted: July 13, 2011 in JavaScript

If you use the range attribute inline to validate against using the jquery.validate plugin 1.8.1, your validation will probably always fail and receive the message “Please enter a value between NaN and {1}.” or “Please enter a value between {0} and NaN.”.

This drove me nuts for almost a whole day looking for a fix. I finally got smart and looked at the current issues in the Github project. “markusblair” submitted a patch, but that was also incorrect.

To correct this issue, modify the jquery.validate.js file on line 852:

		$.each(['rangelength', 'range'], function() {
			if (rules[this]) {
				rules[this] = [Number(rules[this][0]), Number(rules[this][1])];

and replace it with:

		// Patch by Chris Tierney (CF Webtools 7/13/2011)
		// Issue logged at https://github.com/jzaefferer/jquery-validation/issues/112
		$.each(['rangelength', 'range'], function() {
			if (typeof rules[this] == 'string') {
				rules[this] = rules[this].split(",");
			if (rules[this]) {
				rules[this] = [Number(rules[this][0]), Number(rules[this][1])];

Be sure to update your minified version as well and this should solve the range and potentially a similar rangelength method issue immediately.

  1. Gut6 says:

    Great! Thanks for that trick!

  2. Enrique says:

    Nail it buddy!, many thanks!

  3. Ashok G says:

    Thank you very much Chris, it works for me fine.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s