日期:2014-05-16  浏览次数:20412 次

javascript写的几个表单验证方法
请问下各位大虾,我这段javascript代码怎么运行不出呢?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>表单验证</title>
<script>
function CheckForm()
{
   if(document.test.username.value == "")
   {
      alert("用户名不能为空!");
      document.test.username.focus();
  return false;
   }
   return true;
}
function CheckPSW()
{
   if(document.test.password1.value != document.test.password2.value)
   {
      alert("两次输入的密码不一致!");
  return false;
  document.text.password2.focus();
   }
   return true;
}
function onlyNum(e)
{
   if(!((event.keyCode>=48&&event.keyCode<=57))||(event.keyCode>=96&&event.keyCode<=105)
   {
      alert("电话号码请输入数字!");
      return false;
   }
   return true;
}
</script>
</head>
<body>
<form name="test" method="post">
用户名:<input type="text" name="username">
<input type="button" onclick="CheckForm()" name="check" value="检查">
</br>
密码:<input type="password" name="password1"></br>
确认密码:<input  type="password" name="password2">
<input type="button" onclick="CheckPSW()" name="check" value="检查">
</br>
输入电话号码:<input tpye= "text" onkeypress="onlyNum()">
</body>
</html>
------解决方案--------------------
少了括号
if(!((event.keyCode>=48&&event.keyCode<=57))
------解决方案--------------------
(event.keyCode>=96&&event.keyCode<=105))
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>表单验证</title>
<script>
function CheckForm()
{
   if(document.test.username.value == "")
   {
      alert("用户名不能为空!");
      document.test.username.focus();
  return false;
   }
   return true;
}
function CheckPSW()
{
   if(document.test.password1.value != document.test.password2.value)
   {
      alert("两次输入的密码不一致!");
  return false;
  document.text.password2.focus();
   }
   return true;
}
function onlyNum(e)
{
   if(!((event.keyCode>=48&&event.keyCode<=57))
------解决方案--------------------
(event.keyCode>=96&&event.keyCode<=105))
   {
      alert("电话号码请输入数字!");
      return false;
   }
   return true;
}
</script>
</head>
<body>
<form name="test" method="p