Specify 12
as the minimum and maximum value:
captcha: {
required: true,
range: [12, 12]
}
Question
I'm modifying a jquery validation script to include a simple captcha field. I got everything working, except this captha field. On my form, the user have to solve a simple problem, what is 10 + 2. Obviously, the answer is 12, so that is the value the user should add in the field.
Now, if a bot submits the form, this field will either be empty of some other value will be filled into that field, and that will trigger my error message.
My question is, how do I implement this. Here is my validation script
jQuery(document).ready(function($) {
$('#commentform').validate({
rules: {
author: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
},
comment: {
required: true,
minlength: 20
},
captcha: {
required: true,
}
},
messages: {
author: validationtext.author,
email: validationtext.email,
comment: validationtext.comment,
captcha: validationtext.captcha
},
errorElement: "div",
errorPlacement: function(error, element) {
element.before(error);
}
});
});
Solution
Specify 12
as the minimum and maximum value:
captcha: {
required: true,
range: [12, 12]
}