jzaefferer/jquery-validation — Issue #308: rangeWords method has regexp error
Author: superticker
Created: 2012-01-28 22:01:01+00:00
State: open

The _rangeWords_ method in additional-methods.js (v1.9) is missing the escape characters in its second regexp. In addition, the range limits need to be _inclusive_ to make the error message more direct and clearer; therefore, "<" needs to be "<=" instead. The corrected code follows:

jQuery.validator.addMethod("rangeWords", function(value, element, params) {
return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length >= params[0] && value.match(/\b\w+\b/g).length <= params[1];
}, jQuery.validator.format("Please enter from {0} to {1} words."));