We can judge characters or numbers according to the event.keycode of onkeydown events, that is, ASCII chart. ASCII code for the related keyboard key:
refer to the following JavaScript code:
Copy Code code as follows:
<script type = "Text/javascript" >
function IsNumeric (keycode)
{
Return ((keycode >= && keycode <=) | | keycode = 8)
}
</script>
<script type = "Text/javascript" >
function Isalpha (keycode)
{
Return ((keycode >= && keycode <=) | | keycode = 8)
}
</script>
<script type = "Text/javascript" >
function Isalphaornumeric (keycode)
{
Return ((keycode >= && keycode <= 57) | | (KeyCode >= && keycode <= 90) | | KeyCode = 8)
}
</script>
Examples, users can only enter characters and numbers, and use the Onpaste event, cannot paste.
Copy Code code as follows:
<asp:textbox id= "TextBox1" runat= "server" onkeydown = "return Isalphaornumeric (Event.keycode); "Onpaste =" return false; " ></asp:TextBox>