Knockout-Contrib/Knockout-Validation — pull request #392 by JessevanAssen (2014-01-09 18:05:48+00:00)
Title: The 'predicate' validation rule.

The 'predicate' validation rule allows you to add a new validation rule to an observable, without having to create a custom rule. This is useful for rules that only apply once or are highly custom.

The following test case gives a more clear example of the 'predicate' validation rule:

test('Object is Valid and isValid returns True - Demonstrating a more interesting case', function () {
var testObj = ko.observable().extend({ predicate: function(value) { return value >= 10 && value <= 15; } });

testObj(9);
equal(testObj.isValid(), false, '9 < 10, testObj is not Valid');

testObj(10);
equal(testObj.isValid(), true, '10 >= 10 and 10 <= 15, testObj is Valid');

testObj(15);
equal(testObj.isValid(), true, '15 >= 10 and 15 <= 15, testObj is Valid');

testObj(16);
equal(testObj.isValid(), false, '16 > 15, testObj is not Valid');
});