Yes I''ve tried it myself and even went to http://regexlib.com/Default.aspx with no luck. I suppose my request is too basic. All I want to do is prevent users from adding numbers to a field. Any character (UTF8) is fine, except [0-9]. What RegEx returns true for any number of characters as long as there are no numbers? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
def no_digits(field) (field =~ /\d/) == nil end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12/15/06, Taylor Strait <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Yes I''ve tried it myself and even went to > http://regexlib.com/Default.aspx with no luck. I suppose my request is > too basic. All I want to do is prevent users from adding numbers to a > field. Any character (UTF8) is fine, except [0-9]. What RegEx returns > true for any number of characters as long as there are no numbers?If it has to be a regexp to match such a string: /\A[^\d]*\z/ But if possible, it''s usually easier to invert the operator: str !~ /\d/ For example, in a validation: def validate thing !~ /\d/ or errors.add :thing, "cannot contain numbers" end HTH. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi,> Yes I''ve tried it myself and even went to > http://regexlib.com/Default.aspx with no luck. I suppose my > request is > too basic. All I want to do is prevent users from adding numbers to a > field. Any character (UTF8) is fine, except [0-9]. What RegEx > returns > true for any number of characters as long as there are no numbers?/^[^0-9]*$/ should work for you. Regards, Carl Drinkwater | 29degrees 29degrees.co.uk - Bespoke Web Application Development. codegolf.com - Smaller *IS* better. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks everyone - I don''t know why I couldn''t find that anywhere! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-Dec-15 12:13 UTC
Re: RegEx to avoid numbers?
Hi -- On Fri, 15 Dec 2006, George Ogata wrote:> > On 12/15/06, Taylor Strait <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> Yes I''ve tried it myself and even went to >> http://regexlib.com/Default.aspx with no luck. I suppose my request is >> too basic. All I want to do is prevent users from adding numbers to a >> field. Any character (UTF8) is fine, except [0-9]. What RegEx returns >> true for any number of characters as long as there are no numbers? > > If it has to be a regexp to match such a string: > > /\A[^\d]*\z/You can also use \D (non-digit) instead of [^\d]. (I agree that !/\d/ is better anyway though.) David -- Q. What''s a good holiday present for the serious Rails developer? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) aka The Ruby book for Rails developers! Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12/15/06, dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org <dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote:> > Hi -- > > On Fri, 15 Dec 2006, George Ogata wrote: > > /\A[^\d]*\z/ > > You can also use \D (non-digit) instead of [^\d]. (I agree that !/\d/ > is better anyway though.)D''oh! Thanks for the reminder, David. :-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---