if(!email.indexof("@")){不对!呵呵}
其中email是用户输入的那个字符串

解决方案 »

  1.   

    <div align="center">
      <p>&nbsp;</p>
      <form name="form1" method="post" action="validationemail.asp">
        <p>Your Email Address: 
          <input type="text" name="email">
        </p>
        <p>
          <input type="button" name="Button" value="Button" onclick="javascript:checkdata()">
        </p>
      </form>
      <p>&nbsp;</p>
    </div>
    <script language="javascript">
    function checkdata(){
    if (checkemail(document.form1.email,document.form1.email.value)==true){
       document.form1.submit();
    }
    }
    <!--
    function checkemail(objemail,stremailvalue){
    var email=stremailvalue
    var obj=objemail
        var lsDomain=email.split("@")[1]
    var lsUserName=email.split("@")[0]
    var IsIPdomain
    var lnStart
    var intenddomain
    var lnOctect
    var lnOctect2
    var lnIndex
    var intloop
    //' Must have at least 6 characters "[email protected]"
    if (email.length<6){
    obj.focus();
    alert("This email address is invalid!");
    return false;
    }
    //' Look for "@" or "." delimiter
    if (email.indexOf('@', 0) == -1||email.indexOf('.', 0) == -1) {
        obj.focus();
    alert("This email address is invalid!");
    return false;
    }
    //Grab username information
    if(lsUserName==""){
        obj.focus();
    alert("username informations are invalid!");
    return false;
    }
    //Grab domain information "a.ru" and  Domain, sub domain can only have 22 //characters max
    if(lsDomain==""||lsDomain.length<3||lsDomain.length>22){
        obj.focus();
    alert("domain informations are invalid!");
    return false;
     }
     // Split domains and Check to see if the domain is an IP Address
         var lsSubDomainArray=lsDomain.split(".")
     intloop=lsSubDomainArray.length
         intenddomain=lsSubDomainArray[intloop-1]
     //Last domain can have 3 characters max
     if(intenddomain.length>3){
       obj.focus();
    alert("domain informations are invalid,Last domain can have 3 characters max!");
    return false;
     }
     if (intloop==4){
     for (lnIndex = 0; lnIndex < intloop; lnIndex++) {
         lsSubDomain = lsSubDomainArray[lnIndex]
            if (!isNaN(lsSubDomain)==true){
       lnOctect=parseInt(lsSubDomain)
     if (lnOctect > 255||lnOctect < 0){
               obj.focus();
       alert("IP Address is invalid");
               return false;
       }
      else{
        if(lnIndex==0){
      lnOctect2 = parseInt (lnOctect)
     }              // TCP/IP addresses reserved for 'private' networks are:
      // 10.0.0.0       to     10.255.255.255
      // 172.16.0.0     to     172.31.255.255
      // 192.168.0.0    to     192.168.255.255
    lnOctect3=lsSubDomainArray[1]
    switch(lnOctect2){
                  case 10:
                  //Private Network
                    obj.focus();
    alert("This network is Private Network,domain informations are invalid!");
    return false;
      case 172:
        if (lnOctect3 >= 16 && lnOctect3 <= 31){
     obj.focus();
             alert("This network is Private Network,domain informations are invalid!");
                      return false;
     }
     else
     {
      return true;
     }
      case 192:
       //Local Network
                    obj.focus();
    alert("This network is local Network,domain informations are invalid!");
    return false;
      case 127:
      //Local Machine
       obj.focus();
    alert("This network is Local Machine,domain informations are invalid!");
    return false;
      default:
        return true;
      // End private' network check
      }
    }
    }
    else{
       obj.focus();
       alert("IP Address is invalid");
               return false;
    }
    }

        } return true;
    }
    //-->
    </script>
      

  2.   

    ;
      for(var i=0;i<document.mxh.elements.length;i++)
      {
    if(document.mxh.elements[i].checked && (document.mxh.elements[i].name=="requestId"))
          a++;
      }
      if(a==0)
      {
        alert("YOU must selelt one Item")  
      
      

  3.   

    <html>
    <head>
    <script language=javascript>
    // 利用正则运算式验证用户输入是最省事的办法
    function isValid(p, t, s) {
      if (p.test(t.value))
        return true;  if (s != null) {
        t.focus();
        alert(s);
      }
      return false;
    }function isEmail(t, s) {
      return isValid(/^\s*\w+\@\w+(\.\w+)+\s*$/i, t, s);
    }function doSubmit(frm) {
      return isEmail(frm.email, "请输入正确的email地址");
    }
    </script>
    </head>
    <body>
    <form method="post" action="valid.htm" onsubmit="return doSubmit(this)">
      <input name=email>
      <input type="submit">
    </form>
    </body>
    </html>