Only numbers are allowed.
<Input name = "username" type = "text" onkeyup = "value = This. value. Replace (// D +/g,'') ">
Use JavaScript to restrict the input box to only Chinese characters, numbers, integers, and other effects. You can use multiple types of code. I hope it will be helpful to you and pay more attention to iang.com.
First, only numbers and decimal points are allowed.
<Input onkeypress = "Return (/[/D.]/. Test (string. fromcharcode (event. keycode)" style = "ime-mode: Disabled">
Second, the judgment is more detailed, and even 22 .. 2 is not counted as a number.
<SCRIPT>
Function check (){
If (isnan (TT. Value ))
{Alert ("invalid character! ");
TT. value = "";}
}
</SCRIPT>
<Input type = "text" name = "TT" onkeyup = "check ();">
Third, only integers are allowed. In fact, some restrictions can be made based on article 3.
<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>
Conclusion: In fact
Style = "ime-mode: Disabled
This sentence is more practical. To disable the input method. It saves some people the trouble of entering numbers in full angles, and the result cannot be entered to find you crying. It is also a blame for your poor design.
Only numbers are allowed.
<Input name = "username" type = "text" onkeyup = "value = This. value. Replace (// D +/g,'') ">
Only English letters, numbers, and underscores (_) are allowed)
<Input name = "userna 1. Only numbers and decimal points are allowed.
<Input onkeypress = "Return (/[/D.]/. Test (string. fromcharcode (event. keycode)" style = "ime-mode: Disabled">
Second, the judgment is more detailed, and even 22 .. 2 is not counted as a number.
<SCRIPT>
Function check (){
If (isnan (TT. Value ))
{Alert ("invalid character! ");
TT. value = "";}
}
</SCRIPT>
<Input type = "text" name = "TT" onkeyup = "check ();">
Third, only integers are allowed. In fact, some restrictions can be made based on article 3.
<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>
Conclusion: In fact
Style = "ime-mode: Disabled
This sentence is more practical. To disable the input method. It saves some people the trouble of entering numbers in full angles, and the result cannot be entered to find you crying. It is also a blame for your poor design.
Only numbers are allowed.
<Input name = "username" type = "text" onkeyup = "value = This. value. Replace (// D +/g,'') ">
Only English letters, numbers, and underscores (_) are allowed)
<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 @ can be entered @
<Input name = "username" type = "text" onkeyup = "value = value. Replace (/[^/W = @ &] | _/ig,'') ">
Only Chinese characters are allowed.
<Input name = "username" type = "text" onkeyup = "value = value. Replace (/[^/u4e00-/u9fa5]/g,'') ">
Me "type =" text "style =" ime-mode: Disabled ">
<Input name = "username" type = "text" onkeyup = "value = value. Replace (/[^/W/. //]/ig,'') ">
Only English letters, numbers, and @ can be entered @
<Input name = "username" type = "text" onkeyup = "value = value. Replace (/[^/W = @ &] | _/ig,'') ">
Only Chinese characters are allowed.
<Input name = "username" type = "text" onkeyup = "value = value. Replace (/[^/u4e00-/u9fa5]/g,'') ">