柠檬墨绿色 发表于 2016/11/9 15:14

在js中实现邮箱格式的验证方法

  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

  <html>

  <head>

  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

  <title>在此处插入标题</title>

  <script type="text/javascript">

  //判断用户输入的电子邮箱格式是否正确

  function checkEmail(){

  var myforms=document.forms;

  var myemail=myforms.email.value;

  var myReg=/^+@(+\.)+(com|cn|net|org)$/;

  if(myReg.test(myemail)){

  return true;

  }else{

  myspan.innerText="邮箱格式不对!";

  return false;

  }

  }

  </script>

  </head>

  <body>

  <form action="#">

  <table>

  <tr><td>邮箱:<input type="text" id=email></td><td><span id=myspan style="text-size:18pt;color:red;"></span></td></tr>

  <tr><td><input type="submit" value="提交" onclick="return checkEmail()"/></td><td></td></tr>

  function isEmail(email) {

  return /^(((|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.(|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@(((|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|((|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])(|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*(|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+((|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|((|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])(|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*(|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(emailwww.9ask.cn/shangqiu/);

  }

  </table>

  </form>

  </body>

  </html>
页: [1]
查看完整版本: 在js中实现邮箱格式的验证方法