zoukankan      html  css  js  c++  java
  • javascript使用正则表达式验证Email地址

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>测试:用Javascript正则表达式验证Email地址</title>
    </head>
    <body style="background:#fff;">
    <p style="margin-bottom:20px;">
    输入Email地址,点击测试,错误的地址将返回 false...正确的,显示成? 自己猜:
    </p>
    <input type="text" value="" id="mail"/>
    <input type="button" value="测试" id="checkout" onclick="isValidMail(sText)" />
    <script type="text/javascript">
     var sText = document.getElementById('mail').value;
     document.getElementById('mail').onblur = function sValue(){
      sText = this.value;
     }
     
     function isValidMail(sText) {
      var reMail = /^(?:[a-zA-Z0-9]+[_-+.]?)*[a-zA-Z0-9]+@(?:([a-zA-Z0-9]+[_-]?)*[a-zA-Z0-9]+.)+([a-zA-Z]{2,})+$/;
      alert(reMail.test(sText))
     }
    </script>
    </body>
    </html>
  • 相关阅读:
    MySQL数据库生成某一年的日历存储过程
    MySQL随笔(四)
    MySQL索引
    MySQL随笔(三)
    MySQL随笔(二)
    MySQL随笔(一)
    设计模式---策略模式
    数组间相互转换 int[]转list
    安装brew -- Homebrew
    mongodb查询方法
  • 原文地址:https://www.cnblogs.com/zhang-cb/p/6112557.html
Copyright © 2011-2022 走看看