Javascript正则表达式验证邮箱地址

时间:2021-01-18 09:20:43
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <html>
 <head>
 <mce:script language="Javascript1.2"><!--

 function verifyAddress(obj)
 {
  var email = obj.email.value;
  var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
  flag = pattern.test(email);
  if(flag)
  {
   alert("恭喜您!您填写的邮箱地址是正确的!");
   return true;
  }
  else
  {
   alert("请再试一次");
   return false;
  }
 }
 // --></mce:script>
 </head>
 <body>
     <form onSubmit="return verifyAddress(this);">
     <input name="email" type="text">
     <input type="submit">
     </form>
 </body>
 </html>