I have a type="number"
input field. On keyup
I need to strip all characters (including -
) except for 0-9
.
and ,
(I don't care about the order). This proves suprisingly difficult - I haven't found an answer yet.
I got the following:
$input.on('keyup change', () => {
$input.val($input.val().replace(/[^0-9\,\.]/,''));
});
The regex is from this thread (Rails strip all except numbers commas and decimal points), but it doesn't work - if I type 1.
the input vanishes.