Hey all,

Just had a need for this, wondering if it is a candidate for inclusion as it
is only a single line and I can't seem to spot any other way of acheiving
the same functionality in less code.

String.prototype.isNumeric = function() { return (this.match(/^\d+$/) !=
null); }

I used it in the context of:
Event.observe(el,'keypress',function (e) { if (!this.value.isNumeric())
Event.stop(); });
Admittedly, it doesn't cater for decimal points and other locales, but it's
a start?
The regex came from inside the selector code in prototype, so it's used once
at present formula.match(/^\d+$/)

Gareth

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