On Mar 9, 11:12 am, "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

A strategy based on charCodes will fail at least some of the time and
will be much longer, more verbose and less reliable than a regular
expression.  Consider how you are going to test that only one decimal
point is entered, or only two decimal places for currency.

<URL: http://www.merlyn.demon.co.uk/js-valid.htm#VNP >


--
Rob


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to