Permalink
Browse files

Fix maxWords method to include the upper bound, not exclude it. Fixes #…

  • Loading branch information...
1 parent f2f8bcf commit 85b719b8d343de90cad737a3ed49aac14c38c63e @mlynch mlynch committed with jzaefferer Mar 29, 2012
Showing with 5 additions and 3 deletions.
  1. +1 −1 additional-methods.js
  2. +4 −2 test/methods.js
View
2 additional-methods.js
@@ -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) {
View
6 test/methods.js
@@ -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() {

0 comments on commit 85b719b

Please sign in to comment.