I checked the answers to this question here and the best answer I found was this one since it doesn't allow to enter anything but numbers on the input field
function forceNumeric(){
var $input = $(this);
$input.val($input.val().replace(/[^\d]+/g,''));
}
$('body').on('propertychange input', 'input[type="number"]', forceNumeric);
The thing is that I need something like this but that it works for numbers with decimals. Right now this code prevents me from entering dots or commas so I can't enter decimal numbers. Any idea how to adapt it?