(function($){
/*
 * jQuery Constrain Input 0.1
 *
 * Copyright (c) 2008 Mikhail Koryak (dogself.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * 10/15/2008
 */

$.fn.constrainInput = function(config){
   var settings = $.extend({
      allowedCharsRegex: ".*"
   }, config);
   var re = new RegExp(settings.allowedCharsRegex);
   $.each(this, function(){
     var input = $(this);

     var keypressEvent = function(e){
       e= e || window.event;
       var k = e.charCode || e.keyCode || e.which;
       if(e.ctrlKey || e.altKey || k == 8){//Ignore
         return true;
       } else if ((k >= 41 && k <= 122) ||k == 32 || k > 186){//typeable characters
         return (re.test(String.fromCharCode(k)));
       }
       return false;
     }
     input.bind("keypress",keypressEvent);
   });
   return this;
 };
})(jQuery);
