Home > Web Front-end > JS Tutorial > Javascript verification can only enter numbers and a decimal point example_javascript skills

Javascript verification can only enter numbers and a decimal point example_javascript skills

WBOY
Release: 2016-05-16 17:19:12
Original
1241 people have browsed it
Copy code The code is as follows:

function gaga(obj){ // The value allows entering a decimal point and digits
obj.value = obj.value.replace(/[^d.]/g,""); //Replace all non-digits first, except numbers and.
obj.value = obj. value.replace(/^./g,""); //The first one must be a number instead of a number.
obj.value = obj.value.replace(/.{2,}/g,". "); // Ensure that only one appears, not multiple.
obj.value = obj.value.replace(".","$#$").replace(/./g,""). replace("$#$","."); //Guarantee. appears only once and cannot appear more than twice

}


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template