<html>
<body>
<script type="text/javascript">
function noNumbers(e)
{
var keynum
var keychar
var numcheck
if(window.event) // IE
{
keynum = e.keyCode
alert(keynum)
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)//得到输入的字符,不包括键盘的那些功能键,如enter,shift,delete,tab等,
//但一些功能键确实也有自己的keyCode,比如enter的keyCode是13
numcheck = /d/;
return !numcheck.test(keychar)//利用
正则表达式来进行校验
}
</script>
<form>
Type some text (numbers not allowed):
<input type="text" onkeypress="return noNumbers(event)" />
</form>
</html>