How to validate a form with multiple checkboxes to have atleast one checked

前端 未结 11 796
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 23:40

I\'m trying to validate a form using the validate plugin for jquery. I want to require that the user check at least one checkbox in a group in order for the form to be sub

11条回答
  •  失恋的感觉
    2020-12-01 00:05

    The above addMethod by Lod Lawson is not completely correct. It's $.validator and not $.validate and the validator method name cb_selectone requires quotes. Here is a corrected version that I tested:

    $.validator.addMethod('cb_selectone', function(value,element){
        if(element.length>0){
            for(var i=0;i

提交回复
热议问题