Javascript implementation text box can only enter two decimal digits, do not display other characters entered, compatible with ie, firefox is worth your reference.
<Html> <body> script function checkNumber (e, txt) {var key = window. event? E. keyCode: e. which; var keychar = String. fromCharCode (key); var el = document. getElementById ('test'); var msg = document. getElementById ('msg '); reg =/\ d | \. /; var result = reg. test (keychar); if (result) {if (e. keyCode = 46) result =! (Txt. value. split ('.'). length> 1); else result =! (Txt. value. split ('.'). length> 1 & txt. value. split ('.') [1]. length> 1);} if (! Result) {el. className = "warn"; msg. innerHTML = "only numbers can be entered"; return false;} else {el. className = ""; msg. innerHTML = ""; return true ;}} script <p id = "test"> only text boxes with numbers <input type = "text" name = "question. page "onkeypress =" return checkNumber (event, this); "> </p> </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]