jquery validation rules - conditional?
In my jquery validation, is it possible to apply a certain rule only, for example, when the $_GET['name']); is Billybob?
here is a snippet of my rules:
$("#form").validate({
debug: false,
rules: {
semester: "required",
courseno:
{required: true,
courseno: true},
coursename: "required",
"professor[]": "required",
},
开发者_运维知识库for example, coursename is only required when Billybob is present.
Is that even possible?
Can't you do:
var options = {
debug: false,
rules: {
semester: "required",
courseno:
{required: true,
courseno: true},
"professor[]": "required"
};
var coursename = <?php echo $name == 'BillyBob' ? 1 : 0; ?>;
if(coursename) {
options.coursename = 'required';
}
$("#form").validate(options);
精彩评论