Hi everyone, what''s the syntex to check if a field is a number. If my filed is called "phonefiled". thanks for the help in advance. -- 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 -~----------~----~----~----~------~----~------~--~---
wings wrote:> > Hi everyone, what''s the syntex to check if a field is > a number. If my filed is called "phonefiled".validates_numericality_of :phonefiled There are options you should check out at api.rubyonrails.org hth, Bill --~--~---------~--~----~------------~-------~--~----~ 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 Guys,> validates_numericality_of :phonefiledWell, phone "numbers" are almost never numbers. You might have "(02) 9876 5432" or "+61 2 9876 5432". Best to validate against a regexp, e.g.: phone_number =~ /[0-9() +]+/> There are options you should check out at api.rubyonrails.orgYes, their examples even have phone number validation: http://api.rubyonrails.org/classes/ActiveRecord/Validations.html Regards, Dave --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
+1 for Regex. You never know when a user will input any of these valid phone numbers versions (404) 555 1212 404 555-1212 4045551212 etc... RSL On 4/11/07, urbanus <urbanus-f4ka5phDm1zYtjvyW6yDsg@public.gmane.org> wrote:> > > Hi Guys, > > > validates_numericality_of :phonefiled > > Well, phone "numbers" are almost never numbers. You might have "(02) > 9876 5432" or "+61 2 9876 5432". Best to validate against a regexp, > e.g.: > > phone_number =~ /[0-9() +]+/ > > > There are options you should check out at api.rubyonrails.org > > Yes, their examples even have phone number validation: > > http://api.rubyonrails.org/classes/ActiveRecord/Validations.html > > > Regards, > Dave > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 for the help guys! -- 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 -~----------~----~----~----~------~----~------~--~---