试试..
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD> 
  <TITLE> New Document </TITLE> 
</HEAD> 
<BODY> 
  <form name="test" method="post" action="Login.jsp"> 
  用户名: <input type="text" name="username"> 
  <br> 
  年龄: <input type="text" name="age"> 
  <br> 
  性别: <input type="radio" name="sex" value="male" checked>男 
  <input type="radio" name="sex" value="female">女 
  <br> 
  密码: <input type="password" name="pwd"> 
  <br> 
  确认密码: <input type="password" name="pwd1"> 
  <br> 
  爱好: <input type="checkbox" name="intersting" value="football">football 
  <input type="checkbox" name="intersting" value="basketball">basketball 
  <input type="checkbox" name="intersting" value="ruuing">running 
  <br> 
  E-mail: <input type="text" name="email"> 
  <br> 
  <input type="button" value="提交" onclick="javascript:checkForm();"> 
  <input type="reset" value="取消"> 
  </form> 
</BODY> 
</HTML> <script language="javascript"> 
var myReg = /^[A-Za-z0-9]\w+@(\w+\.)+[A-Za-z0-9]$/;
function checkForm() 

var theForm=document.test; 
if(theForm.username.value=="") 

alert("please input username!"); 
theForm.username.focus(); 

else if(theForm.age.value=="") 

alert("please input age"); 
theForm.age.focus(); 

else if((theForm.age.value <1)&&(theForm.age.value>100)) 

alert("age must between 1 and 100"); 
theForm.age.focus(); 

else if(theForm.pwd.value=="") 

alert("please input password"); 
theForm.pwd.focus(); 

else if(theForm.pwd1.value=="") 

alert("please input password again!"); 
theForm.pwd1.focus(); 

else if(theForm.pwd1.value != theForm.pwd.value) 

alert("password not match"); 
theForm.pwd1.focus(); 

else if(theForm.email.value=="") 

alert("please input E-mail"); 
theForm.email.focus(); 

    else if(!(myReg.test(theForm.email.value))) 

alert("E-mail not match!"); 
theForm.email.focus(); 

else 

alert("提交成功"); 
theForm.submit(); 


</script> 

解决方案 »

  1.   

    写错了
    /^[A-Za-z0-9]\w+@(\w+\.)+[A-Za-z0-9]+$/
      

  2.   

    还有个问题就是年龄部分不能判断是否在1到100之间的范围,我猜要用到parseInt()方法转换,再来比较,是不是?到底应该怎样修改才严谨?
      

  3.   

    不是表达式的原因噢
    var myReg = new RegExp("/^[_a-z0-9]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/"); 
    改成
    var myReg = /^[A-Za-z0-9]\w+@(\w+\.)+[A-Za-z0-9]+$/
    你试试  我在本机上是调试成功的.....