validate: Enhanced min/max/rangeWords (in additional-methods.js) to strip html before counting; good when counting words in a richtext editor

This commit is contained in:
Jörn Zaeffferer
2009-09-15 09:34:52 +00:00
parent acb5c9226c
commit 25bf058bfd
3 changed files with 41 additions and 13 deletions

View File

@@ -4,9 +4,9 @@ function methodTest( methodName ) {
var v = jQuery("#form").validate();
var method = $.validator.methods[methodName];
var element = $("#firstname")[0];
return function(value) {
return function(value, param) {
element.value = value;
return method.call( v, value, element );
return method.call( v, value, element, param );
};
}
@@ -488,6 +488,24 @@ test("time", function() {
ok( !method("30:00"), "Invalid time" );
});
test("minWords", function() {
var method = methodTest("minWords");
ok( method("hello worlds", 2), "plain text, valid" );
ok( method("<b>hello</b> world", 2), "html, valid" );
ok( !method("hello", 2), "plain text, invalid" );
ok( !method("<b>world</b>", 2), "html, invalid" );
ok( !method("world <br/>", 2), "html, invalid" );
});
test("maxWords", function() {
var method = methodTest("maxWords");
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" );
});
function testCardTypeByNumber(number, cardname, expected) {
$("#cardnumber").val(number);
var actual = $("#ccform").valid();