zoukankan      html  css  js  c++  java
  • JavaScript 检查 email 地址的正则表达式

    JavaScript 检查 email 地址的正则表达式
    1.代码(1)
    <html>
    <head>
    <title>Checking an email address - Version 01</title>
    <script type="text/javascript" language="javascript">
    <!-- //
    function IsMatchingAddress(str){
        var myRegExp = /[a-z0-9-]{1,30}@[a-z0-9-]{1,65}.[a-z]{3}/ ;
        return myRegExp.test(str)
    }
     
    function TestGuess(){
     
    var EmailAddr = "asdf@asdf.net".toLowerCase();
    alert(IsMatchingAddress(EmailAddr));
    }
    // -->
    </script>
    </head>
    <body>
    <h3>This page allows you to enter and check
     an email address such as asdf@java2s.com.com</h3>
    <form>http://www.huiyi8.com/yinxiao/
    <button type="Button" onclick="TestGuess()">
    Click here to enter email address</button>
    </form>
    </body>
    </html>
    2. [代码]方法2     

    <html>
    <head>
    <title>Checking an email address - Version 02</title>
    <script type="text/javascript" language="javascript">
    <!-- //
    中国音效网
    function IsMatchingAddress(str){
        var myRegExp = /[a-z0-9-.]{1,30}@[a-z0-9-]{1,65}.(com|net|org|info|biz|([a-z]{2,3}.[a-z]{2}))/ ;
        return myRegExp.test(str)
    }
     
    function TestGuess(){
        var EmailAddr = "asdf@java2s.com".toLowerCase();
        alert(IsMatchingAddress(EmailAddr));
    }
    // -->
    </script>
    </head>
    <body>
    <h3>This page allows you to enter and check an email address
     such as asdf@java2s.com,</h3>
    <form>
    <button type="Button" onclick="TestGuess()">
    Click here to enter email address</button>
    </form>
    </body>
    </html>
    3. [代码]方法3  

    <html>
    <head>
    <title>E-mail Example</title>
    <script type="text/javascript">
        function isValidEmail(sText) {
            var reEmail = /^(?:w+.?)*w+@(?:w+.)+w+$/;
            return reEmail.test(sText);
        }
        function validate() {
            var oInput1 = document.getElementById("txt1");
            if (isValidEmail(oInput1.value)) {
                alert("Valid");
            } else {
                alert("Invalid!");
            }
     
        }
    </script>
    </head>
    <body>
        <P>E-mail Address: <input type="text" id="txt1" /><br />
        <input type="button" value="Validate" onclick="validate()" /></p>
     
    </body>
    </html>

  • 相关阅读:
    Qt快速入门学习笔记(基础篇)
    IDEA 创建文件夹总默认根节点问题解决
    SpringBoot 集成MyBatis 中的@MapperScan注解
    Springboot项目下mybatis报错:Invalid bound statement (not found)
    IDEA maven项目查自动查看依赖关系,解决包冲突问题
    Mybatis-generator/通用Mapper/Mybatis-Plus对比
    Mybatis
    在一个已经使用mybatis的项目里引入mybatis-plus,结果不能共存
    springboot整合图像数据库Neo4j
    Spring Boot:Boot2.0版本整合Neo4j
  • 原文地址:https://www.cnblogs.com/xkzy/p/3865785.html
Copyright © 2011-2022 走看看