Description
1 can only enter 0 to 9 and decimal points
2 can only paste the number
3 can't drag content in
4 prohibit the use of input method
With the above, we can start.
Example (compatible IE, Firefox and other browsers)
The code is as follows |
Copy Code |
<input onkeypress= "Return event.keycode>=48&&event.keycode<=57| | Event.keycode==46 " Onpaste= "Return!clipboarddata.getdata (' text '). Match (/d/)" Ondragenter= "return False" Style= "Ime-mode:disabled" > |
Cases
The code is as follows |
Copy Code |
<input name= "username" type= "text" onkeyup= "Value=this.value.replace (/d+/g, ')" > |
Cases
The code is as follows |
Copy Code |
<script language=javascript> function Onlynum () { if (!) ( EVENT.KEYCODE==46) &&! (event.keycode==8) &&! (event.keycode==37) &&! (event.keycode==39)) if (!) ( (event.keycode>=48&&event.keycode<=57) | | (event.keycode>=96&&event.keycode<=105))) Event.returnvalue=false; } </script><input onkeydown= "Onlynum ();" Style= "ime-mode:disabled> |
Cases
You can only enter a number to lose a decimal point.
The code is as follows |
Copy Code |
<input onkeyup= "if (isNaN (value)) ExecCommand (' Undo ') ' onafterpaste= ' if (isNaN (value)) ExecCommand (' Undo ') > <input name=txt1 onchange= "if (/d/.test (this.value)) {alert (' can only enter numbers '); this.value= ';} ' > |
Cases
The code is as follows |
Copy Code |
function CheckNumber (e) { var keynum; var Keychar; var Numcheck; if (window.event) {//ie keynum = e.ke Ycode; } else if (E.which) {//! IE keynum = E.which; } Keychar = String.fromCharCode (keynum);//Convert keyboard code to actual character Numcheck =/d/; return numcheck.test (Keychar);//Return!numcheck.test (Keychar); Cannot enter kanji } call method <input type= "text" onkeypress= "return CheckNumber (Event)" value= "0"/> |