You Can Still Type Non-Numbers In A Type Number HTML Input
We can set the type property of an HTML input to number to accept only numbers. But we can still type in something like 00001213400012 or 1-5-5-5--442-, which are not quite what I usually define as normal numbers. By the way, I wrote that input values are treated as type string even if the type of the input is set to be number. Try type in 000123 or 1-2-53 in this input which is set to be type number. Type: Input: Using Number or parseFolat We can use parseFloat() or Number() method to convert the type of input values from string to number, now try to type in 000123 or 1-2-352. Type: Input: <input oninput="show(this)" type="number" /><br /> <div>Type: <span id="showType"></span></div> <div>Input: <span id="showNo"></span></div> <script> function show(t){ var value = Number(t.value);//or parseFloat(t.value); showType.innerHTML = typeof(value); showNo...