密码校验(密码必须同时包含大写、小写、数字和特殊字符其中三项且至少8位)

时间:2025-03-20 09:02:55

//密码

var regex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,30}');

if(!(this.newPassword1)){

// this.$toast("密码必须同时包含大写、小写、数字和特殊字符其中三项且至少8位");

return;

}

//手机号

  $("#mobile").blur(function () {
        let _this = $(this).val();
        let reg = /^1[3456789]\d{9}$/;
        if (_this === "" || _this == null) {
            $(".span-text:eq(6)").html("该字段为必填字段");
        } else if (!(_this)) {
            $(".span-text:eq(6)").html("手机号码有误");
        }else {
            $(".span-text:eq(6)").html("");
        }
    });

官网:/demo/

<script>
    //使用layui的表单校验
    (['form'],function () {
        var form = ;
        ({
            account: function(value, item){ //value:表单的值、item:表单的DOM对象
                if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                    return '登录名不能有特殊字符';
                }
                if(/(^\_)|(\__)|(\_+$)/.test(value)){
                    return '登录名首尾不能出现下划线\'_\'';
                }
                if(/^\d+\d+\d$/.test(value)){
                    return '登录名不能全为数字';
                }
                if( >25){
                    return '登录名长度在1到25位之间';
                }
            }
            ,password: function(value, item){
                if(!new RegExp("(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{6,30}").test(value)){
                    return '密码必须包含大小写字母、数字和特殊字符(长度大于6位)';
                }
            }
            ,checkPass: function(value, item){
                let _this = $("#checkPass").val();
                let _password = $("#password").val();
                if(_this !== _password){
                    return '与上次输入密码不同';
                }
            }
            ,userName: function(value, item){
                if( >30){
                    return '长度在1到30位之间,中文算两个';
                }
            }
            ,mobile: function(value, item){
                let reg = /^1[3456789]\d{9}$/;
                if(!(value)){
                    return '手机号码有误';
                }
            }
        });
    })

</script>