js 验证电子邮箱

//userinfo是from表单名(name),email是文本框名(name)

 if(document.userinfo.email.value.length!=0)  {
    if (document.userinfo.email.value.charAt(0)=="." ||        
         document.userinfo.email.value.charAt(0)=="@"||       
         document.userinfo.email.value.indexOf('@', 0) == -1 ||
         document.userinfo.email.value.indexOf('.', 0) == -1 ||
         document.userinfo.email.value.lastIndexOf("@")==document.userinfo.email.value.length-1 ||
         document.userinfo.email.value.lastIndexOf(".")==document.userinfo.email.value.length-1)
     {
      alert("Email地址格式不正确!");
      document.userinfo.email.focus();
      return false;
      }
   }else
  {
   alert("Email不能为空!");
   document.userinfo.email.focus();
   return false;
   }


 

原文地址:https://www.cnblogs.com/fuge/p/2342562.html