I use replace()
to remove non-numeric characters from an input field, like so:
<input type="number" oninput="this.value = this.value.replace(/[^\d]/g,'');">
It works well, but when I enter a few numbers followed by a minus sign or a dot (on Android it has to be two dots), the whole field is cleared. This only happens when the input type is set to "number", not when it's set to "text", but I need "number" to show the numeric keyboard on mobile.
Why could this happening?
To clarify, I only want to allow [0-9], not other possibly numeric characters like [.-e].