diff --git a/select2.js b/select2.js
index afb9aa49..f0f72d5a 100644
--- a/select2.js
+++ b/select2.js
@@ -1251,6 +1251,15 @@ the specific language governing permissions and limitations under the Apache Lic
render("
" + opts.formatSearching() + "");
}
+ if (opts.maximumInputLength && search.val().length > opts.maximumInputLength) {
+ if (checkFormatter(opts.formatInputTooLong, "formatInputTooLong")) {
+ render("" + opts.formatInputTooLong(search.val(), opts.maximumInputLength) + "");
+ } else {
+ render("");
+ }
+ return;
+ }
+
// give the tokenizer a chance to pre-process the input
input = this.tokenize();
if (input != undefined && input != null) {
@@ -2411,11 +2420,13 @@ the specific language governing permissions and limitations under the Apache Lic
formatResultCssClass: function(data) {return undefined;},
formatNoMatches: function () { return "No matches found"; },
formatInputTooShort: function (input, min) { var n = min - input.length; return "Please enter " + n + " more character" + (n == 1? "" : "s"); },
+ formatInputTooLong: function (input, max) { var n = input.length - max; return "Please enter " + n + " less character" + (n == 1? "" : "s"); },
formatSelectionTooBig: function (limit) { return "You can only select " + limit + " item" + (limit == 1 ? "" : "s"); },
formatLoadMore: function (pageNumber) { return "Loading more results..."; },
formatSearching: function () { return "Searching..."; },
minimumResultsForSearch: 0,
minimumInputLength: 0,
+ maximumInputLength: null,
maximumSelectionSize: 0,
id: function (e) { return e.id; },
matcher: function(term, text) {