jQuery form preview using the Instagram plugin
//$(document).ready(fn) can be shortened to $(fn)
//you can use it to avoid global scope pollution so we place everything in here
$(function () {

  //IDs are unique, so we drop input
  //cache values that are static and used more than once
  var instagramHashtag = $('#instagram_hashtag_hashtag');
  var pattern = /(^#|\s#)([a-z0-9]+)/gi;
  var instaContainer = $('.instagram');
  var timer;

  function doneTyping(tags) {

    //why create the timer check? besides, if the function was called and
    //tags was blank, the loop wouldn't run since there are no matches

    //these variables are only used here, so declare them in here
    var tagsa = tags.match(pattern);
    var length = tagsa.length;
    var i = 0; 

    while(i &lt; length) {
      instaContainer.instagram({
        hash: tagsa[i++].replace('#', ''),
        clientId: 'instagramclientid',
        show: 4
      });
    }
  }

  //use jQuery on, which accepts a map of events
  //that way, you write the selector part only once
  instagramHashtag.on({
    keypress: function () {
      if(timer) clearTimeout(timer);
      timer = setTimeout(function () {
        doneTyping(instagramHashtag.val());
      }, 350);
    },
    blur: function () {
      doneTyping(instagramHashtag.val());
    }
  });
});