When the user presses a key, I want to remove characters that are not in the range 0-9, but this code isn't working: (jsfiddle)
$('input').on('keypress', function(event){
var char = String.fromCharCode(event.which)
var txt = $(this).val()
if (!txt.match(/^[0-9]*$/)){
var changeTo = txt.replace(char, '')
$(this).val(changeTo).change();
}
});
What am I doing wrong? Thanks