没有问题检测数字也不用这么麻烦,用if (!isNaN(form.input1.value)) alert("这里必须填写数字!");或者
<input type=text onkeypress="return checkKeyPress()">
<script>
function checkKeyPress()
{
if ((window.event.keyCode<48&&window.event.keyCode!=13) || window.event.keyCode>57)
window.event.keyCode=0;
return true;}</script>
<input type=text onkeypress="return checkKeyPress()">
<script>
function checkKeyPress()
{
if ((window.event.keyCode<48&&window.event.keyCode!=13) || window.event.keyCode>57)
window.event.keyCode=0;
return true;}</script>
var numberFormat=/^\d+$/;
var toCheckString=form1.input1.value;
if (!numberFormat.test(toCheckString))
{
alert("Number required.");
return false;
}