Maximum Input Length

in select2 when I search the maximumInputLength. I want to show a message with that. how can i achieve this?

Hi, Neeraj–

When you say “search the maximumInputLength”, do you mean enter a search term that contains maximumInputLength characters? If so, I believe your question is how to detect that the user’s search term has hit the maxiumumInputLength.

Your best bet is to attach an input event handler to the Select2 input field and when the length of the current input equals maximumInputLength, display your message in whichever method you prefer (for example, window.alert()):

$('input.select2-search__field').on('input', function(event) {
  if ( === maximumInputLength) {
    window.alert('You have reached the maximum input length.');

Note that the event handler doesn’t have direct access to the value you set for the maximumInputLength configuration property. You will need to store that value somewhere (for example, in a “global” variable) that your event handler can access it.