jquery - form validate rules required depends

前端 未结 1 2011
暖寄归人
暖寄归人 2021-01-14 22:00

Can somebody give me a primer on how to use the validate, rules, required, depends. I have some partial code but not sure

1条回答
  •  抹茶落季
    2021-01-14 22:23

    $("#form2").validate({
    rules: {
        firstname: {     //This rule applies to the $('#form2 input[name="firstname"]') selector
    
            required: {  //This can be a true/false boolean, string, or a complex field using depends.
    
                depends: function () { //depends takes a function pointer that
                                       //returns a value, informing the rule 
                                       //if it is required. In this case, always true.
    
                    $(this).val($.trim($(this).val()));
    
                    return true;
                }
            },
    
            minlength: 2 // the minimum length of text in the field is 2 characters.
        },
    

    0 讨论(0)
提交回复
热议问题