Found a few probs - home/end/arrow keys don't work and you can hold shift
and type symbols.
I used it as a base though...
I am just going to complete some testing on my handler and then i'll put it
up in case someone can see some obvious optimisations.
Gareth
On 3/9/07, Mark Holton <[EMAIL PROTECTED]> wrote:
>
> ...here's a 'numbersonly' js function that I like..... this would take
> care of the numbers only part... and you could easily adapt to meet your
> needs:
> cheers,
> Mark
>
> ...in the element you want to validate, simply add:
> onkeypress="return numbersonly(event)"
>
> put this JS at the top of the page:
> <script type="text/javascript">
> // verifies only a number was typed into the form element
> function numbersonly(e){
> var unicode=e.charCode? e.charCode : e.keyCode
> // if (unicode!=8||unicode!=9)
> if (unicode<8||unicode>9)
> {
> //if the key isn't the backspace key or tab key (which we
> should allow)
> if (unicode<48||unicode>57) //if not a number
> return false //disable key press
> }
> }
> </script>
>
>
>
> On 3/8/07, Gareth Evans <[EMAIL PROTECTED]> wrote:
> >
> > I have a feeling instantiating a regex on every key press to ensure the
> > key pressed is numeric may be a tad overkill?
> >
> >
> > On 3/9/07, David Dashifen Kees <[EMAIL PROTECTED] > wrote:
> > >
> > >
> > > Sounds to me like you need a regular expression that can accurately
> > > describe the data that's valid and then check that the value of the
> > > field matches the regular expression on a key press.
> > >
> > > -- Dash --
> > >
> > > agrath wrote:
> > > > I have a requirement to validate input to a field as numeric only-
> > > >
> > > > A number of approaches could be used here, but I need to create 3
> > > > different validators:
> > > >
> > > > 1) Currency
> > > > 2) Numbers, including decimals and , i guess
> > > > 3) Integers only
> > > >
> > > > I'm thinking an observer on the keydown event of the field I want to
> > >
> > > > validate, the question is how do we validate the data being entered
> > > is
> > > > correct and close all the loopholes.
> > > >
> > > > In a previous scenario such as this, I experienced major issues with
> > > > users holding the shift key and typing number keys (to get symbols
> > > > entered) as well as copy-and-paste being able to paste text data, so
> > > > ended up needing to recheck and clear on-blur as well...
> > > > The result was a massive script that was total bloatware for the
> > > > operation.
> > > >
> > > > I was wondering how some of you might approach the problem.
> > > >
> > > > Prototype 1.5.0 is being used in the project.
> > > >
> > > > The way I see it, I can either force validation by only allowing
> > > > numeric digits to be entered, and deny non numeric digits, or go
> > > with
> > > > a remember-the-milk type input validation, with an icon on the end
> > > of
> > > > the field that indicates if the data is parsed correctly and prevent
> > >
> > > > the form from being submitted unless all validation rules are met.
> > > > Whilst I like the second option (validation icon) I think it will
> > > > prove to be more trouble than it's worth.
> > > >
> > > > What do you guys think?
> > > >
> > > >
> > > > >
> > > >
> > > >
> > >
> > >
> > >
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---