This article example describes the method of controlling js to input only numbers and decimal points in text boxes. Share it for your reference. The specific implementation method is as follows:
The code copy is as follows: function clearNoNum(obj) {
obj.value = obj.value.replace(/[^/d.]/g, "");//Clear characters other than "number" and "."
obj.value = obj.value.replace(/^/./g, "");//verify that the first character is a number instead of.
obj.value = obj.value.replace(//.{2,}/g, ".");//Retain only the first one. Clear the excess.
obj.value = obj.value.replace(".", "$#$").replace(//./g,"").replace("$#$", ".");
}
The usage is as follows:
Copy the code code as follows: <input name="input1" onkeyup="clearNoNum(this)">
I hope this article will be helpful to everyone's JavaScript programming.