<form action=""> <input type="number" required="" min=0 step="0.01" > <button>click</button> </form> 

I make a withdrawal of currency, taking into account kopecks, then the last 2 decimal places (with a full stop or comma). In chrome, everything works out perfectly, for example, I enter 5.555 or 5.555, validation does not allow it, in 5.555 it does not allow BUT 5,555 to validate. How to solve this problem?

  • one
    Unfortunately, while different browsers, form elements with HTML5 input types of number or datetime type are displayed differently, and this causes a lot of problems. The solution is to use a custom input element. - Dmitry Polyanin

1 answer 1

 function myFunction() { var x = document.getElementById("myInput").value, y = x[x.length - 1], r; if(y === ','){ r = x.substring(0,x.length - 1) + '.'; document.getElementById("myInput").value = r; } } 
 <input type="text" id="myInput" oninput="myFunction()"> <p id="demo"></p> 

You may want the option of replacing commas with dots