First, you should place this code in the hooks/footer-extras.php file:

 AppGini.numericOnly = function(fieldname){
 var field = $j('#' + fieldname), val = field.val();
 if(val == parseFloat(val)) return;
 val = parseFloat(val.replace(/[^d.-]/g,''));
 if(isNaN(val)){ field.val(''); return; }
 }, 1000);

Next, also in the hooks folder, create a file named tablename-dv.js (where tablename is the name of the concerned table) if it’s not already there, and add this code to it:


Change field1 and field2 in the above code to the actual names of the fields that you want to set to accept only numeric values. Add more lines if you have more fields or remove a line if you have only one numeric field.

The above code would remove any non-numeric characters that the user types, on the fly. And it would still allow negative sign and decimal point.