<script language=javascript>
//要求一
if(document.text1.value==''||document.text2.value=='')
{
  alert('1');
}
//要求二
email=document.text1.value;
if((at=email.indexOf("@"))<0){
email_ok=false;
}
if((dot=email.lastIndexOf("."))<0){
email_ok=false;
}
if(at>dot||dot>=email.length-1){
email_ok=false;
}
if(!email_ok){
alert("填写 EMail 错误!");
return false;
}
//要求三
if(document.text1.value<=0)
{
  alert('3');
}

解决方案 »

  1.   

    var text1=document.getElementById("text1");
    var text2=document.getElementById("text2");if(text1.value=="" || text2.value=="")
    {
       alert("please input first!!");
       return false;
    }if(parseInt(text2.value)<=0)
    {
       alert("text2 should >0!!");
       return false;
    }if(text1.value.indexOf("@")<=0 || text1.value.indexOf("@")==text1.value.length-1)
    {
       alert("text1 should be validated email address!!");
       return false;
    }
      

  2.   

    <html>
    <head>
    <script language="JavaScript">
    <!--
    function check(){
    if(text1.value=="" && text2.value==""){
       alert("不能都为空!"); return;
    }
    if(!testEmail(text1.value)){
       alert("Email格式不合法!"); return ;
    }
    if(parseInt(text2.value,10)<=0){
       alert("文本框值应该大于零!"); return ;
    }

    }
    function testEmail(str){
      var reg=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
      return reg.test(str);
    }
    //-->
    </script>
    </head>
    <body>
    <input type="text" name="text1" value="[email protected]">
    <input type="text" name="text2" value="-20">
    <input type="button" onclick="check()" value="check">
    </body>
    </html>