我正在以交易规模和最小投资的形式进行验证。在这里,最低投资必须<交易规模。我已经从this answer获得了帮助,但它比较了数字位数而不是算术比较,它还给出了一条错误消息:
请输入不超过3个字符。
我想要"Enter minimum investment less than deal size."
$('.deal-crud-validation').validate({
rules: {
digits: true,
number: true,
mininvestment: getRule()
},
message:{
maxlength: "Enter minimum investment less than deal size"
}
});
$('.dealvalue').change(function () {
$('.mininvestment').rules('remove', 'maxlength');
$('.mininvestment').rules('add', getRule());
});
答案 0 :(得分:1)
我从以下方面获得了帮助:jquery validation for more than min value获得解决方案
`$.validator.addMethod("greaterThan",
function (value, element, param) {
var $min = $(param);
if (this.settings.onfocusout) {
$min.off(".validate-greaterThan").on("blur.validate-greaterThan", function () {
$(element).valid();
});
}
return parseInt(value) < parseInt($min.val());
}, "Enter minimum investment less than deal size");
$('.deal-crud-validation').validate({
rules: {
mininvestment: {
greaterThan: '.dealvalue'
}
}
});