(function($)
	{
		$.fn.constrainInput = function(config)
		{
			var settings = $.extend(
				{  
					allowedCharsRegex: ".*",
					maxInt:	false,
					allowEnter: true
				}, config);  
			var re = new RegExp(settings.allowedCharsRegex);
			$.each(this, function()
				{
					var input = $(this);
					
					var value_before = $(this).val();
					
					this.keypressEvent = function(e)
					{
						e= e || window.event;  
						var k = e.charCode || e.keyCode || e.which;
						
						if (settings.allowEnter && k == 13){
							return true;
						} else 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;  
					}
					
					this.keyupEvent = function(e)
					{
						if (settings.maxInt != false)
						{
							if ($(this).val() > settings.maxInt)
							{
								$(this).val(value_before);
							}
						}
						
						value_before = $(this).val();
						
						return true;  
					}
					
					input.bind("keypress",this.keypressEvent);
					input.bind("keyup",this.keyupEvent);
				});  
			return this;  
		};  
	})(jQuery);  
