Home >Web Front-end >JS Tutorial >How to control the text box to only input numbers and decimal points using js_javascript skills
How to control the text box to only input numbers and decimal points using js_javascript skills
WBOYOriginal
2016-05-16 16:10:221214browse
The example in this article describes the method of using js to control the text box to only input numbers and decimal points. Share it with everyone for your reference. The specific implementation method is as follows:
function clearNoNum(obj) {
obj.value = obj.value.replace(/[^d.]/g, "");//Clear characters other than "numbers" and "."
obj.value = obj.value.replace(/^./g, "");//Verify that the first character is a number and not .
obj.value = obj.value.replace(/.{2,}/g, "."); //Only keep the first one. Clear the redundant.
obj.value = obj.value.replace(".", "$#$").replace(/./g,"").replace("$#$", ".");
}
I hope this article will be helpful to everyone’s JavaScript programming design.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn