superyucong

(其中的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-z\d$@$!%*?&]{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("错误!");
        }
    }

 

分类:

技术点:

相关文章: