Forum: Ruby on Rails NOOB: Numeric only input...can it be done on client?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D802ba476bb7ccfb1f43a4e89194fc8a?d=identicon&s=25 James Ricci (Guest)
on 2006-01-17 19:22
(Received via mailing list)
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
D90ef6808433e63203e15a5c2dadb0bb?d=identicon&s=25 Ben Reubenstien (Guest)
on 2006-01-17 19:31
(Received via mailing list)
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
7fc50b5df035274f5acdc21ee7b3b599?d=identicon&s=25 Jim Campbell (Guest)
on 2006-01-17 19:34
(Received via mailing list)
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) {

}
119af50160cabfe1fb6f2f05f5018c64?d=identicon&s=25 James Ludlow (Guest)
on 2006-01-17 19:34
(Received via mailing list)
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
7fc50b5df035274f5acdc21ee7b3b599?d=identicon&s=25 Jim Campbell (Guest)
on 2006-01-17 19:34
(Received via mailing list)
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
D802ba476bb7ccfb1f43a4e89194fc8a?d=identicon&s=25 James Ricci (Guest)
on 2006-01-17 20:01
(Received via mailing list)
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
This topic is locked and can not be replied to.