0

how is make a jquery validdata number ? (i not use of plugin)

description: i want input text accept only number.

<input type="text" name"number">
Jennifer Anthony
  • 2,227
  • 10
  • 37
  • 56
  • Have a look at this question - http://stackoverflow.com/questions/995183/how-to-allow-only-numeric-0-9-in-html-inputbox-using-jquery – ipr101 Sep 03 '11 at 09:35
  • For the new browsers (**chrome and opera**) it is available as type, and other browsers just interpret it as text. It will be a touch of the future to add it, and for verification on the older browsers to use JavaScript\jQuery.[demo](http://www.w3schools.com/html5/tryit.asp?filename=tryhtml5_input_type_number) – Bakudan Sep 03 '11 at 09:47

1 Answers1

0

I think this question is already asked.In there are also answers not using plugin.I take it from here How to allow only numeric (0-9) in HTML inputbox using jQuery?

    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));
        });
    });
};

$("#yourTextBoxName").ForceNumericOnly();
Community
  • 1
  • 1
Cenk
  • 82
  • 4