/** * @version 1.0.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 length = this.length, match, expr = '=='; if ('string' === $.type(required)) { match = required.match(/([>': match = (length > required); break; case '>=': match = (length >= required); break; case '<': match = (length < required); break; case '<=': match = (length <= 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);