/** * @version 1 * @requires jQuery */ (function ($) { "use strict"; /** * @param {Number} [required=1] Required size e.g. 1, '!= 1', '>= 5', '< 10' * @param {String|Function} [message] Error message * @return {jQuery} */ $.fn.required = function (required, message) { required = required || 1; var size = this.size(), match, expr = '=='; if ('string' === $.type(required)) { match = required.match(/([>': match = (size > required); break; case '>=': match = (size >= required); break; case '<': match = (size < required); break; case '<=': match = (size <= required); break; default: throw new SyntaxError('$.fn.required: Unknown expressions "' + expr + '"'); } if (!match) { if ('function' === $.type(message)) { message(this); } else { if (null == message) { message = 'Required node not found' + (this.selector ? ' "' + this.selector + '"' : ''); } throw new Error(message); } } return this; }; })(jQuery);