onlyNumber.html test code:
<html><head><script language="JavaScript" >function onlyNumber(obj){//Get whether the first character is a negative sign var t = obj.value.charAt(0); //Replace all non-numeric first, except for the numbers and. obj.value = obj.value.replace(/[^/d/.]/g,''); // Make sure that the first one is a number instead of. obj.value = obj.value.replace(/^/./g,''); //Can only appear one. without multiple. obj.value = obj.value.replace(//.{2,}/g,'.'); //Please guarantee. Only once, not more than twice obj.value = obj.value.replace('.','$#$').replace(//./g,'').replace('$#$','.');//If the first digit is a negative sign, add if(t == '-'){obj.value = '-'+obj.value;}}</script><meta http-equiv="content-Type" content="text/html;charset=gb2312"><meta name="keywords" content="" /><meta name="description" content="" /><title>Restricted text boxes can only enter numbers|| can only be numbers and decimal points|| can only be integers and floating points</title></head><body><hr/>Text box that can only enter numbers: <input onkeyup="this.value=this.value.replace(//D/g,'')" onblur="this.value=this.value.replace(//D/g,'')"/><br/><hr/>Text box that can only enter numbers and decimal points: <input onkeyup="value=value.replace(/[^/d/.]/g,'')" onblur="value=value.replace(/[^/d/.]/g,'')"/><br/><hr/> Text box with only digits and only one decimal point (the decimal point cannot start, it can be at the end, and the first digit is allowed to add a negative sign, that is, a floating point number): <input onkeyup="onlyNumber(this)" onblur="onlyNumber(this)" /><hr//</body></html>The above code briefly introduces you to the knowledge that limits the number of numbers in text boxes to be input || can only be numbers and decimal points || can only be integers and floating points. I hope it can help you!