try this http://www.texotela.co.uk/code/jquery/numeric/
----- Original Message ----- From: "Caio Landau" <wonho...@gmail.com>
To: "jQuery (English)" <jquery-en@googlegroups.com> Sent: Friday, July 17, 2009 9:45 AM Subject: [jQuery] Re: Input that allows only numbers. So let me get it, key's code numbered between (and including) 48 and 57 are numbers? Ok, I got it, thank you :) On Jul 17, 11:18 am, Matt Zagrabelny <mzagr...@d.umn.edu> wrote:
On Thu, 2009-07-16 at 16:12 -0700, Caio Landau wrote: > Well, that a simple question, I hope. I have an input (<input > type="text" />) on my page, and I want it to only accept numbers, so > if the user types anything that's not a number, it will be removed > instantly. > A simplified example just to illustrate: > <body> > <input type="text" name="numbers" /> <!-- I want this input to accept > only numbers --> > </body> This works for me... <html> <head> <script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery/jquery.js"></script> <script language="javascript" type="text/javascript"> $(function() { $('#numbersonly').keypress( function(event) { return ((event.which >= 48) && (event.which <= 57)); } );}); </script> </head> <body> <input id="numbersonly" name="first_name"/> </body> </html> Cheers, -- Matt Zagrabelny - mzagr...@d.umn.edu - (218) 726 8844 University of Minnesota Duluth Information Technology Systems & Services PGP key 1024D/84E22DA2 2005-11-07 Fingerprint: 78F9 18B3 EF58 56F5 FC85 C5CA 53E7 887F 84E2 2DA2 He is not a fool who gives up what he cannot keep to gain what he cannot lose. -Jim Elliot signature.asc < 1KViewDownload