• 正则


    1 用户名正则

    //用户名正则,4到16位(字母,数字,下划线,减号)
    var uPattern = /^[a-zA-Z0-9_-]{4,16}$/;
    //输出 true
    console.log(uPattern.test("caibaojian"));

    2 Email正则

    //Email正则
    var ePattern = /^([A-Za-z0-9_-.])+@([A-Za-z0-9_-.])+.([A-Za-z]{2,4})$/;
    //输出 true
    console.log(ePattern.test("99154507@qq.com"));

    3 密码强度正则

    //密码强度正则,最少6位,包括至少1个大写字母,1个小写字母,1个数字,1个特殊字符
    var pPattern = /^.*(?=.{6,})(?=.*d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/;
    //输出 true
    console.log("=="+pPattern.test("caibaojian#"));
    
    

    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta charset="utf-8">
    </head>
    <body>
    <script type="text/javascript">
    fChkMail=function(szMail){
    var szReg=/^[A-Za-zd]+([-_.][A-Za-zd]+)*@([A-Za-zd]+[-.])+[A-Za-zd]{2,5}$/; var bChk=szReg.test(szMail);
    return bChk;
    }
    </script>
    <script type="text/javascript">
    fChkMail = function(username){
    var uPattern = /^[a-zA-Z0-9_-]{4,16}$/;
    console.log(uPattern.test("caibaojian"));
    }
    </script>
    <script type="text/javascript">
    fChkMail = function(password){
    var pPattern = /^.*(?=.{6,})(?=.*d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/;
    console.log("=="+pPattern.test("caibaojian#"));
    }

    </script>
    <h3>登录<br></h3>
    <input type="text" id="username" value=""/>
    <input type="button" value="用户名" onclick="alert(fChkMail(document.getElementById('username').value));"><br><br>
    <input type="text" id="Mail" value="" />
    <input type="button" value="验证邮箱地址" onclick="alert(fChkMail(document.getElementById('Mail').value));"/> <br><br>

    <input type="text" id="password" value=""/>
    <input type="button" value="密码" onclick="alert(fChkMail(document.getElementById('password').value));"><br>

    </body>
    </html>

  • 相关阅读:
    CS231n assignment3 Q1 Image Captioning with Vanilla RNNs
    使用tensorflow预测函数的参数值(a simple task)
    CS231n assignment2 Q5 TensorFlow on CIFAR-10
    CS231n assignment2 Q4 Convolutional Networks
    HDU 1561 The more, The Better
    HDU4003 Find Metal Mineral
    poj 1947 Rebuilding Roads
    2090 背包
    poj 2408 Apple Tree
    奔跑的xiaodao
  • 原文地址:https://www.cnblogs.com/scg0624/p/9867783.html
Copyright © 2020-2023  润新知