title: text field lock in jquery auto-complete - only allow submissions within autocomplete options
body: <p>Hei, am looking for help in my code that allows an autocomplete, only within a specified data array. So only data within the auto complete array is allowed to be entered. for example if user has typed iran01 then user wont allow to type 01 because iran01 is not valid . or for example if user type NNN after iran then it wud be iranNNN which is also not valid . Then only iran shud be in textbox which is valid entry . can anyone tell how to do this.</p>
  
  <p>can any one tell how to get this behavior . </p>
  
  <pre><code>$(document).ready(function () {
                       data = ["iran", "iraq", "Libya", "india"];
                      $("#autocomplete").autocomplete(data)
                 });
  
                 $('input#autocomplete').bind('keypress keyup', function(){
  
                   if ($.inArray($(this).val(), data) == -1){
                      $(this).val('');
                      $("#result").html("No match found!" + $(this).val());
                }
  
             });
  
              $('input#autocomplete').result(function (event, data, formatted) {
                  $("#result").html(!data ? "No match found!" : "Selected: " + formatted);
  
              }).keyup(function () {
                  $(this).search();
  
              });
  
           } 
      });
  </code></pre>