jquery validate 自定义验证方法

jquery validate 自定义验证方法
jQuery.validator.addMethod("stringCheck", function (value, element) {
    //return this.optional(element) || /^[\u0391-\uFFE5\w]+$/.test(value);
    if ($("#txtProductName").val().length < 10) {
        return false;
    }
    else {
        return true;
    }
}, "请输入适合的长度");

//验证
function validateFrom() {
    $("#form1").validate({
        rules: {
            txtProductName: {
                required: true,
                stringCheck: true
            },
            txtMarketPrice: {
                required: true,
                number: true
            },
            txtIntegral: {
                required: true,
                digits: true
            }
        },
        messages: {
            txtProductName: {
                required: "请输入礼品名称"
            },
            txtMarketPrice: {
                required: "请输入市场价"
            },
            txtIntegral: {
                required: "请输入兑换积分"
            }
        }
        , success: function (label) {
            label.html("&nbsp;").attr("class", "success").siblings("label").remove();
        },
        errorPlacement: function (error, element) {
            $(element).next("span").find(".success").remove();
            error.appendTo(element.next("span"));
        }
    });

}
jquery validate 自定义验证方法

 

自定义验证信息

jquery validate 自定义验证方法
jQuery.validator.addMethod("stringCheck", function (value, element) {
    //return this.optional(element) || /^[\u0391-\uFFE5\w]+$/.test(value);
    if ($("#txtProductName").val().length < 10) {
        $.validator.messages["stringCheck"] = "错了";
        return false;
    }
    else {
        $.validator.messages["stringCheck"] = "对了";
        return true;
    }

});

//验证
function validateFrom() {
    $("#form1").validate({
        rules: {
            txtProductName: {
                required: true,
                stringCheck: true
            },
            txtMarketPrice: {
                required: true,
                number: true
            },
            txtIntegral: {
                required: true,
                digits: true
            }
        },
        messages: {
            txtProductName: {
                required: "请输入礼品名称"
            },
            txtMarketPrice: {
                required: "请输入市场价"
            },
            txtIntegral: {
                required: "请输入兑换积分"
            }
        }
        , success: function (label) {
            label.html("&nbsp;").attr("class", "success").siblings("label").remove();
        },
        errorPlacement: function (error, element) {
            $(element).next("span").find(".success").remove();
            error.appendTo(element.next("span"));
        }
    });

}
jquery validate 自定义验证方法

jquery validate 自定义验证方法,布布扣,bubuko.com

jquery validate 自定义验证方法

上一篇:Safari里使用JsonView


下一篇:【转】phpmyadmin,终于把你给整好了!