I must prevent the user to insert a non-numeric value in an input type text with knockout:
Here my HTML:
<input data-bind="value: myModel.myNumber, valueUpdate: 'afterkeydown', event: { change: validateMyNumber }" type="number" />
Here the js:
self.validateMyNumber = function (data, event) {
var input = data.myModel.myNumber();
if (input == "")
{
}
};
I can't find some logic to write inside the validateMyNumber function... when I press the button, it it is not a number I lost the old value in my model and I get an empty string... in the textBox nothing changes instead... I just want that if I insert a non-numeric value I must block the insert in the textbox... How can I do?