What you are doing is like 'Shotgun'. It will take care of invalid input not only at editing but even if there is some wrong value is supplied at rendering(getting data from source).
You have to define a custom component to take care of user input.
var columnDefs = [
{
field: "value",
editable: true,
cellEditorSelector: function (params) {
if (params.data.type === 'age') {
return {
component: 'numericCellEditor'
};
}
return null;
...
...
Custom Editor Component Ref Documentation
function NumericCellEditor() {
}
NumericCellEditor.prototype.init = function (params) {
this.eInput = document.createElement('input');
if (isCharNumeric(params.charPress)) {
this.eInput.value = params.charPress;
} else {
if (params.value !== undefined && params.value !== null) {
this.eInput.value = params.value;
}
}
var that = this;
this.eInput.addEventListener('keypress', function (event) {
if (!isKeyPressedNumeric(event)) {
that.eInput.focus();
if (event.preventDefault) event.preventDefault();
} else if (that.isKeyPressedNavigation(event)){
event.stopPropagation();
}
});
var charPressIsNotANumber = params.charPress && ('1234567890'.indexOf(params.charPress) < 0);
this.cancelBeforeStart = charPressIsNotANumber;
};
NumericCellEditor.prototype.isKeyPressedNavigation = function (event){
return event.keyCode===39
|| event.keyCode===37;
};
NumericCellEditor.prototype.getGui = function () {
return this.eInput;
};
NumericCellEditor.prototype.afterGuiAttached = function () {
this.eInput.focus();
};
NumericCellEditor.prototype.isCancelBeforeStart = function () {
return this.cancelBeforeStart;
};
NumericCellEditor.prototype.isCancelAfterEnd = function () {
var value = this.getValue();
return value.indexOf('007') >= 0;
};
NumericCellEditor.prototype.getValue = function () {
return this.eInput.value;
};
NumericCellEditor.prototype.destroy = function () {
};
NumericCellEditor.prototype.isPopup = function () {
return false;
};