Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 17:19:121220browse
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

}


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