/*

  Author - Rudolf Naprstek
  Website - http://www.thimbleopensource.com/tutorials-snippets/jquery-plugin-filter-text-input
  Release - 14th April 2010

*/

(function($){  
  
    $.fn.extend({   

        filter_input: function(options) {  

            var defaults = {  
                regex:".*"
            }  
                  
            var options =  $.extend(defaults, options);  
  
            return this.each(function() {  
              var input = $(this);
              var regex = new RegExp(options.regex);
              input.keypress(function(event) {
                var key = event.charCode ? event.charCode : event.keyCode ? event.keyCode : 0;
                if (key == 13) return true;
                var string = String.fromCharCode(key);
                if (regex.test(string)) {
                  return true;
                } 
                return false;
                
              });
            });  
        }  
    });  
      
})(jQuery);  