James Ricci
2006-Jan-17 17:43 UTC
[Rails] NOOB: Numeric only input...can it be done on client?
I was wondering if there''s a way to limit what a user is typing on the keyboard to only valid numeric input. Is there a simple plugin or something which would allow this? I guess with AJAX it could also be one. Has anyone already solved this requirement? Thanks in advance. James -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060117/c2286973/attachment.html
Ben Reubenstien
2006-Jan-17 17:53 UTC
[Rails] NOOB: Numeric only input...can it be done on client?
Javascript should get the job done. A quick google for "numeric entry only javascript" had this result... Might work well: http://www.pbdr.com/vbtips/asp/JavaNumberValid.htm On 1/17/06, James Ricci <james@riccinursery.com> wrote:> > I was wondering if there''s a way to limit what a user is typing on the > keyboard to only valid numeric input. Is there a simple plugin or something > which would allow this? I guess with AJAX it could also be one. Has anyone > already solved this requirement? Thanks in advance. > > > > James > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Ben Reubenstein benr@x-cr.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060117/db9d95bb/attachment.html
Jim Campbell
2006-Jan-17 17:55 UTC
[Rails] NOOB: Numeric only input...can it be done on client?
Sure, and there''s no need to complicate it with a server call. A simple way to do it is to define a string of characters (in your case, numbers), then have each keystroke check that string for characters. Something like this would work: var numerals = "0123456789"; function checkInput(myField) { } On 1/17/06, James Ricci <james@riccinursery.com> wrote:> > I was wondering if there''s a way to limit what a user is typing on the > keyboard to only valid numeric input. Is there a simple plugin or something > which would allow this? I guess with AJAX it could also be one. Has anyone > already solved this requirement? Thanks in advance. > > > > James > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060117/5e9ca785/attachment.html
James Ludlow
2006-Jan-17 17:55 UTC
[Rails] NOOB: Numeric only input...can it be done on client?
On 1/17/06, James Ricci <james@riccinursery.com> wrote:> I was wondering if there''s a way to limit what a user is typing on the > keyboard to only valid numeric input. Is there a simple plugin or something > which would allow this? I guess with AJAX it could also be one. Has anyone > already solved this requirement? Thanks in advance.Keep in mind that even if you get this to work in the browser, your server-side code should never trust this data to be in a valid format. You still need to do validation on the server. As for your question, it seems like this would be pretty easy with JavaScript and the onkeypress event handler. -- James
Jim Campbell
2006-Jan-17 17:57 UTC
[Rails] NOOB: Numeric only input...can it be done on client?
Hah - oops, I hit "Enter" by accident. I was going to type in a function, but Googling for "Javascript restrict input" turns up a good example as is (although i''m not sure if it''s the most graceful): http://www.felgall.com/jstip44.htm - Jim On 1/17/06, Jim Campbell <phong3d@gmail.com> wrote:> > Sure, and there''s no need to complicate it with a server call. A simple > way to do it is to define a string of characters (in your case, numbers), > then have each keystroke check that string for characters. Something like > this would work: > > var numerals = "0123456789"; > function checkInput(myField) { > > } > > On 1/17/06, James Ricci < james@riccinursery.com> wrote: > > > > I was wondering if there''s a way to limit what a user is typing on the > > keyboard to only valid numeric input. Is there a simple plugin or something > > which would allow this? I guess with AJAX it could also be one. Has anyone > > already solved this requirement? Thanks in advance. > > > > > > > > James > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060117/9607ac67/attachment-0001.html
James Ricci
2006-Jan-17 18:25 UTC
[Rails] NOOB: Numeric only input...can it be done on client?
Thanks very much for all the helpful advice everyone. James _____ From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Jim Campbell Sent: Tuesday, January 17, 2006 11:57 AM To: rails@lists.rubyonrails.org Subject: Re: [Rails] NOOB: Numeric only input...can it be done on client? Hah - oops, I hit "Enter" by accident. I was going to type in a function, but Googling for "Javascript restrict input" turns up a good example as is (although i''m not sure if it''s the most graceful): http://www.felgall.com/jstip44.htm - Jim On 1/17/06, Jim Campbell < phong3d@gmail.com <mailto:phong3d@gmail.com> > wrote: Sure, and there''s no need to complicate it with a server call. A simple way to do it is to define a string of characters (in your case, numbers), then have each keystroke check that string for characters. Something like this would work: var numerals = "0123456789"; function checkInput(myField) { } On 1/17/06, James Ricci < <mailto:james@riccinursery.com> james@riccinursery.com> wrote: I was wondering if there''s a way to limit what a user is typing on the keyboard to only valid numeric input. Is there a simple plugin or something which would allow this? I guess with AJAX it could also be one. Has anyone already solved this requirement? Thanks in advance. James _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060117/2c4170f0/attachment-0001.html