Native Rules

seteam1 edited this page Nov 21, 2012 · 5 revisions

Required:

var myObj = ko.observable().extend({ required: true });
var myObj = ko.observable().extend({ required: { onlyIf: function() { return true; } } });

Min:

var myObj = ko.observable().extend({ min: 2 });

Max:

var myObj = ko.observable().extend({ max: 99 });

MinLength:

var myObj = ko.observable().extend({ minLength: 3 });

MaxLength:

var myObj = ko.observable().extend({ maxLength: 12 });

Pattern:

var myObj = ko.observable().extend({ pattern: '^[a-z0-9].$' });

Step: Works really well with min and max

var myObj = ko.observable().extend({ step: 3 });

Email:

var myObj = ko.observable().extend({ email: true });

Equal:

var otherObj = ko.observable();
var myObj = ko.observable().extend({ equal: otherObj });
//or
var myObj = ko.observable().extend({ equal: 2 }); // in case you just want it to equal something

Not Equal:

var otherObj = ko.observable();
var myObj = ko.observable().extend({ notEqual: otherObj });
//or
var myObj = ko.observable().extend({ notEqual: 2 }); // in case you just want it to NOT equal something else

Date:

var myObj = ko.observable().extend({ date: true });

DateISO:

var myObj = ko.observable().extend({ dateISO: true });

Number:

var myObj = ko.observable().extend({ number: true });

Digit:

var myObj = ko.observable().extend({ digit: true });