JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/knockout-validation/1.0.2/knockout.validation.min.js"></script>
<input data-bind="value: age"/>
JavaScript
var ChildModel = function(cookieAge){
var self = this,
age = cookieAge || "";
self.age = ko.observable(age).extend({
validation: [{
validator: function (val) {
return !ko.validation.utils.isEmptyVal(val) && parseInt(val,10) !== 0;
},
message: 'Please say how old this child is.'
},{
validator: function (val, someOtherVal) {
if (!isNaN(val)) {
if (val > someOtherVal) {
this.message = "This child's age must be less than or equal to 29.";
return false;
}
return true;
}
if (val !== '<1') {
this.message = "(contains text) For Children less than 1, please use '<1'";
return false;
}
return true;
},
params: 29
}]
});
};
ko.applyBindings(new ChildModel());