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;
   }

 


 

posted @ 2012-02-03 13:15  偶不是大叔  阅读(1627)  评论(0编辑  收藏  举报