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
WBOY
Release: 2016-05-16 16:10:22
Original
1213 people have browsed it
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("$#$", ".");
}
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