Skip to content

Commit

Permalink
Fix maxWords method to include the upper bound, not exclude it. Fixes j…
Browse files Browse the repository at this point in the history
  • Loading branch information
mlynch authored and jzaefferer committed Mar 29, 2012
1 parent f2f8bcf commit 85b719b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion additional-methods.js
Expand Up @@ -20,7 +20,7 @@
.replace(/[0-9.(),;:!?%#$'"_+=\/-]*/g,'');
}
jQuery.validator.addMethod("maxWords", function(value, element, params) {
return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length < params;
return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length <= params;
}, jQuery.validator.format("Please enter {0} words or less."));

jQuery.validator.addMethod("minWords", function(value, element, params) {
Expand Down
6 changes: 4 additions & 2 deletions test/methods.js
Expand Up @@ -527,8 +527,10 @@ test("maxWords", function() {
ok( method("hello", 2), "plain text, valid" );
ok( method("<b>world</b>", 2), "html, valid" );
ok( method("world <br/>", 2), "html, valid" );
ok( !method("hello worlds", 2), "plain text, invalid" );
ok( !method("<b>hello</b> world", 2), "html, invalid" );
ok( method("hello worlds", 2), "plain text, valid" );
ok( method("<b>hello</b> world", 2), "html, valid" );
ok( !method("hello my world", 2), "plain text, invalid" );
ok( !method("<b>hello</b> my world", 2), "html, invalid" );
});

test("pattern", function() {
Expand Down

0 comments on commit 85b719b

Please sign in to comment.