js 正则表达式验证邮箱事例

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

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页