时间:2021-07-01 10:21:17 帮助过:58人阅读
<script type = "text/javascript">
function isNumeric(keyCode)
{
return ((keyCode >= 48 && keyCode <= 57) || keyCode == 8)
}
</script>
<script type = "text/javascript">
function isAlpha(keyCode)
{
return ((keyCode >= 65 && keyCode <= 90) || keyCode == 8)
}
</script>
<script type = "text/javascript">
function isAlphaOrNumeric(keyCode)
{
return ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || keyCode == 8)
}
</script>
例子,用户只能输入字符和数字,并使用onpaste事件,不能粘贴。
代码如下:
<asp:TextBox ID="TextBox1" runat="server" onkeydown = "return isAlphaOrNumeric(event.keyCode);" onpaste = "return false;"></asp:TextBox>