Cannot enter Chinese
<input type= "text" name= "TextField" onkeyup= "This.value=this.value.replace (/[^/da-z_]/ig, ');" />
Only numbers and underscores can be entered
<input onkeypress= "Return (/[/d_]/.test (String.fromCharCode (Event.keycode))" style= "ime-mode:disabled"/>
Only numbers and decimal points can be entered
<input onkeypress= "return (/[/d.) /.test (String.fromCharCode (Event.keycode))) "style=" ime-mode:disabled "/>
Allow only Chinese characters to be entered </br>
<input name= "username" type= "text" onkeyup= "Value=value.replace (/[^/u4e00-/u9fa5]/g, ')" >
One is to allow only numbers and decimal points to be entered.
<input onkeypress= "return (/[/d.) /.test (String.fromCharCode (Event.keycode))) "style=" ime-mode:disabled ">
Second, the judgment is more detailed, even 22. 2 That's not a number.
<script>
function Check () {
if (IsNaN (Tt.value))
{alert ("illegal character! ");
Tt.value= "";}
}
</script>
<input type= "text" Name= "tt" onkeyup= "check ();" >
The third, only allows the input of integers. In fact, we can also make some restrictions according to the third article extrapolate.
<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>
The conclusion, in fact
Style= "ime-mode:disabled
This sentence is more practical. Turn off the IME. Save some people to open the full-width input number, the result input does not come in to find you kutianmalei, also blame you design bad.
Allow only numeric input
<input name= "username" type= "text" onkeyup= "Value=this.value.replace (//d+/g, ')" >
Value=value.replace (/[^\d\.) /g, ");
Only English letters, numbers, and underscores are allowed (the following two methods are implemented)
<input name= "username" type= "text" style= "ime-mode:disabled" >
<input name= "username" type= "text" onkeyup= "Value=value.replace (/[^/w/.//]/ig, ')" >
Only English letters, numbers and &[email are allowed protected]
<input name= "username" type= "text" onkeyup= "Value=value.replace (/[^/[email protected]&]|_/ig, ')" >
Allow only Chinese characters to be entered
<input name= "username" type= "text" onkeyup= "Value=value.replace (/[^/u4e00-/u9fa5]/g, ')" >
JavaScript regular expression control input can only enter a number