(function($) { $.fn.bootstrapValidator.validators.choice = { html5Attributes: ['min', 'max'], /** * Check if the number of checked boxes are less or more than a given number * * @param {BootstrapValidator} validator The validator plugin instance * @param {jQuery} $field Field element * @param {Object} options Consists of following keys: * - min * - max * At least one of two keys is required * @returns {Boolean} */ validate: function(validator, $field, options) { var numChoices = validator .getFieldElements($field.attr('data-bv-field')) .filter(':checked') .length; if ((options.min && numChoices < options.min) || (options.max && numChoices > options.max)) { return false; } return true; } }; }(window.jQuery));