Javascript controls the text box to only enter numbers and decimal places. js text box
This article describes how to enter only numbers and decimal places in the Javascript control text box. Share it with you for your reference. The specific implementation method is as follows:
Copy codeThe Code 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 a number.
Obj. value = obj. value. replace (/\. {2,}/g, "."); // only keep the first. Clear unnecessary.
Obj. value = obj. value. replace (". "," $ # $ "). replace (/\. /g ,""). replace ("$ # $ ",". ");
}
The usage is as follows:
Copy codeThe Code is as follows: <input name = "input1" onkeyup = "clearNoNum (this)">
I hope this article will help you design javascript programs.