﻿(function($) {
    $.fn.numeric = function(options) {
        var opts = $.extend($.fn.numeric.defaults, options);
        return this.each(function() {
            $(this).keydown(function(e) {
                var key = e.charCode || e.keyCode || 0;
                if (opts.allowControlKeys && isControlKey(key)) {
                    return true;
                }
                return ((key >= 48 && key <= 57) || (key >= 96 && key <= 105));
            });
        });
    };
    function isControlKey(key) {
        var controlKeys = new Array(8, 9, 46, 37, 38, 39, 40);
        return $.inArray(key, controlKeys) > -1;
    }
    $.fn.numeric.defaults = { allowControlKeys: true };
})(jQuery);
