var parth=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;

解决方案 »

  1.   

    我的判断function isCharsInBag (s, bag)
    {  
      var i;
      // Search through string's characters one by one.
      // If character is in bag, append to returnString.  for (i = 0; i < s.length; i++)
      {   
          // Check that current character isn't whitespace.
          var c = s.charAt(i);
          if (bag.indexOf(c) == -1) return false;
      }
      return true;
    }function isEmail (s)
    {
        // is s Empty?
        if (isEmpty(s))
    {
    window.alert("输入的E-mail地址不能为空,请输入!");
    mobj = eval("document.wizard.tr_email");
            mobj.focus()
            mobj.select()
    return false;
    }
    //is s contain whitespace
        if (isWhitespace(s))
    {
    window.alert("输入的E-mail地址中不能包含空格符,请重新输入!");
    mobj = eval("document.wizard.tr_email");
            mobj.focus()
            mobj.select()
    return false;
    }   // there must be >= 1 character before @, so we
       // start looking at character position 1
       // (i.e. second character)
       var i = 1;
       var len = s.length; if (len > 50)
    {
    window.alert("email地址长度不能超过50位!");
    mobj = eval("document.wizard.tr_email");
            mobj.focus()
            mobj.select()
    return false;
    }

    pos1 = s.indexOf("@");
    pos2 = s.indexOf(".");
    pos3 = s.lastIndexOf("@");
    pos4 = s.lastIndexOf(".");
    //check '@' and '.' is not first or last character
    if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len))  
    {
    window.alert("请输入有效的E-mail地址!");
    mobj = eval("document.wizard.tr_email");
            mobj.focus()
            mobj.select()
    return false;
    }
    else
    {
    //check @. or .@
    if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1) 
      || ( pos1 != pos3 )  //find two @
      || ( pos4 < pos3 ) ) //. should behind the '@'  
    {
    window.alert("请输入有效的E-mail地址!");
    mobj = eval("document.wizard.tr_email");
                mobj.focus()
                mobj.select()
    return false;
    }
    } if ( !isCharsInBag( s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@"))
    {
    window.alert("email地址中只能包含字符ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@\n" + "请重新输入" );
    mobj = eval("document.wizard.tr_email");
            mobj.focus()
    return false;
    }
    //is s contain invalid characters
    /*
    var badChar = "><,[]{}?/+=|\\'\":;!#$%^&()`"; 
    if ( isCharsInBag( s, badChar))
    {
    alert("请不要在email地址中输入字符 " + badChar + "\n" );
    alert("请重新输入" );
    return false;
    }
    */
    return true;
    }function checkdata()
    {
    if ( !isEmail(document.form1.email1.value) )
       return false
    }return true
    }