zoukankan      html  css  js  c++  java
  • 正则表达式验证用户信息

    (其中的str为接收到的用户所输入的用户名)

    用户名正则:4到16位(字母,数字,下划线,减号):

        function checkUser(str){
            var user = /^[a-zA-Z]w{3,15}$/;
            if (user.test(str))
             {
                alert("正确!");
             }
            else {
                alert("错误!");
            }
        }

    密码强度正则:最少6位,包括至少1个大写字母,1个小写字母,1个数字,1个特殊字符:

        function checkPwd(str){
            var pwd = /^(?=.*[a-z])(?=.*[A-Z])(?=.*d)(?=.*[$@$!%*?&])[A-Za-zd$@$!%*?&]{6,}$/;
            if (pwd.test(str))
             {
                alert("正确!");
             }
            else {
                alert("错误!");
            }
        }

     Email正则:

        function checkEmail(str){
            var email = /^[a-z0-9]w+@[a-z0-9]{2,3}(.[a-z]{2,3}){1,2}$/;
            if (email.test(str)) 
                {
                    alert("正确!");
                } 
            else {
                    alert("错误!");
            }
        }

    身份证号码正则:

        function checkIdNo(str){
            var IdNo = /(^d{18}$)|(^d{17}(d|X|x)$)/;
            if (IdNo.test(str))
             {
                alert("正确!");
             } 
            else {
                alert("错误!");
            }
        }
  • 相关阅读:
    牛客算法周周练18A
    洛谷P2580
    Codeforces 617E
    SPOJ 3267
    Codeforces Round #661 (Div. 3) 解题报告(ABCD)
    Codeforces 1399D
    Codeforces 1399C
    Codeforces 1399B
    Codeforces 1399A
    牛客算法周周练18 解题报告(ABCE)
  • 原文地址:https://www.cnblogs.com/superyucong/p/9877073.html
Copyright © 2011-2022 走看看