我很新的jQuery验证有人请纠正我在哪里我错了我想要添加的规则。jQuery验证添加规则
<script>
$("#form").validate({
focusInvalid: false,
rules: {
ownership: {
required: true
},
vin: {
required: true,
validateVin: true
},
// Same for other fields
},
messages: {
ownership: "This field is required.",
vin: "Invalid VIN",
// Repeat for other fields
}
});
// create your custom rule
jQuery.validator.addMethod(validateVin(this.value, Number($("#vehicleyear").val()))) {
function validateVin(vin, date) {
var re;
if (date >= 1981) {
re = new RegExp("^[A-HJ-NPR-Z\\d]{8}[\\dX][A-HJ-NPR-Z\\d]{2}\\d{6}$");
} else if (date < 1981) {
re = new RegExp("^[A-Z\\d]{2,17}$");
} else {
}
return vin.match(re);
}, 'Please enter valid VIN.'});
</script>
据说这是为了检查两个领域,首先它会检查哪一年被拾取vehicleyear
则根据当年它检查输入vin
,看看正则表达式匹配。如果它不正确,那么它应该说无效的vin。
当我运行我的它甚至不使用regEx,但我不明白为什么。任何帮助,将不胜感激!
检查您的控制台(chrome - f12 - console)您可能有一些错误。 – user1477388 2015-02-08 13:12:00