How does input number prohibit the entry of mathematical symbols such as e and decimal points?

I need to enter pure numbers in an input box, so I take it for granted that I write

 <input type="number" >

then found that it is possible to enter mathematical symbols such as e and decimal point. Look it up on the Internet, and modify it as follows

 <input type="number" v-model="fromSize" onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))">

but found that it still has no effect, or you can enter e and decimal point and mathematical symbols, I would like to ask how to solve this?


Mobile, you can try to add pattern, pop-up keyboard only numbers, very easy to use. Regular matching before submission is generally sufficient.

<input type="number" pattern="[0-9]*" placeholder="">

on the web side, in addition to onKeypress,onkeyup, you should also consider copying and pasting and so on, which is not recommended. It is better to detect, prompt or roll back to the last legal value

in change/blur.

does not quite understand your idea, you do not enter e, then you can monitor fromSize, if it is e or has a decimal point, just give a hint and clear the value.


but found that it still has no effect, or you can enter e and decimal point and mathematical symbols, I would like to ask how to solve this?

how do I lose? This rule can only input numbers.
http://jsfiddle.net/631807682.

but it doesn't really work, because if you change the Chinese input method onKeypress , it will be useless. You've used v-model . watch won't it be over at once?


oninput = "value=value.replace (/ [^ d] / g answer')"


write an @ blur or @ change or @ input event to parseInt () the value

Menu