Return to Snippet

Revision: 47293
at June 4, 2011 06:39 by vagrantradio


Initial Code
//usage
$("#yourTextBoxName").ForceNumericOnly();

//plugin
jQuery.fn.ForceNumericOnly =
function()
{
    return this.each(function()
    {
        $(this).keydown(function(e)
        {
            var key = e.charCode || e.keyCode || 0;
            // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
            return (
                key == 8 || 
                key == 9 ||
                key == 46 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105));
        })
    })
};

Initial URL

                                

Initial Description

                                

Initial Title
Numeric Only jQuery Plugin

Initial Tags

                                

Initial Language
jQuery