Thriving K.
2009-Sep-29 03:40 UTC
How to validate presence of phone number or mobile phone.
In my model of user.rb there are phone number and mobile number. i want to validate if phone number and mobile number are exist or not(not neccessary to do both). how to do that -- Posted via http://www.ruby-forum.com/.
Sijo Kg
2009-Sep-29 04:36 UTC
Re: How to validate presence of phone number or mobile phone.
Hi As an example validates_format_of :phone_number,:allow_nil => true,:with => /regex here/ Sijo -- Posted via http://www.ruby-forum.com/.
Thriving K.
2009-Sep-29 04:47 UTC
Re: How to validate presence of phone number or mobile phone.
i don''t understand... could you please explain more also , i thought i use the wrong word. There are two field like this Mobile Phone................ Phone ..................... validate if mobile phone Or phone is filled , not neccessary to field both, but filled at least one. -- Posted via http://www.ruby-forum.com/.
Sijo Kg
2009-Sep-29 05:05 UTC
Re: How to validate presence of phone number or mobile phone.
Hi What I understood is you have to check presence of phone number and mobile number But not at the same time Right? If so please try the following Assuming you have the fields phone_number and mobile_number validates_presence_of :mobile_number,:if => :phone_number_blank_check validates_presence_of :phone_number,:if => :mobile_number_blank_check def phone_number_blank_check self.phone_number.blank? end def mobile_number_blank_check self.mobile_number.blank? end Sijo -- Posted via http://www.ruby-forum.com/.
Thriving K.
2009-Sep-29 05:13 UTC
Re: How to validate presence of phone number or mobile phone.
Thank you -- Posted via http://www.ruby-forum.com/.
Thriving K.
2009-Sep-29 06:32 UTC
Re: How to validate presence of phone number or mobile phone.
I found another problem when i use this code validates_presence_of :mobile_number,:if => :phone_number_blank_check validates_presence_of :phone_number,:if => :mobile_number_blank_check def phone_number_blank_check self.phone_number.blank? end def mobile_number_blank_check self.mobile_number.blank? end when both field leave blank, it happened two message told that mobile_number can''t be blank and phone_number can''t be blank i want it to appear only one message tell that phone number or mobile number can''t be blank, how could i do that. -- Posted via http://www.ruby-forum.com/.
Mukund
2009-Sep-29 06:37 UTC
Re: How to validate presence of phone number or mobile phone.
Write your own validate routine instead of using the helpers. On Sep 29, 11:32 am, "Thriving K." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I found another problem when i use this code > > validates_presence_of :mobile_number,:if => :phone_number_blank_check > validates_presence_of :phone_number,:if => :mobile_number_blank_check > > def phone_number_blank_check > self.phone_number.blank? > end > > def mobile_number_blank_check > self.mobile_number.blank? > end > > when both field leave blank, it happened two message told that > mobile_number can''t be blank and phone_number can''t be blank > > i want it to appear only one message tell that > phone number or mobile number can''t be blank, how could i do that. > -- > Posted viahttp://www.ruby-forum.com/.
Thriving K.
2009-Sep-29 07:12 UTC
Re: How to validate presence of phone number or mobile phone.
Mukund wrote:> Write your own validate routine instead of using the helpers. > > On Sep 29, 11:32�am, "Thriving K." <rails-mailing-l...@andreas-s.net>Is there any guideline for that... please. -- Posted via http://www.ruby-forum.com/.
Sijo Kg
2009-Sep-29 07:55 UTC
Re: How to validate presence of phone number or mobile phone.
Hi> i want it to appear only one message tell that > phone number or mobile number can''t be blank, how could i do that.You can do like def validate validate_phone_and_mobile([mobile_number,phone_number]) end def validate_phone_and_mobile(numbers) errors.add_to_base("phone number and/or mobile number can''t be blank") if (numbers.first.blank? or numbers.second.blank?) or (numbers.first.blank? and numbers.second.blank?) end Sijo -- Posted via http://www.ruby-forum.com/.
John T.
2009-Sep-29 13:34 UTC
Re: How to validate presence of phone number or mobile phone.
Thriving K. wrote:> Mukund wrote: >> Write your own validate routine instead of using the helpers. >> >> On Sep 29, 11:32�am, "Thriving K." <rails-mailing-l...@andreas-s.net> > > > Is there any guideline for that... please.www.google.com -- Posted via http://www.ruby-forum.com/.
I have something like this in one of my apps for email and cell: validate :presence_of_email_or_cell def presence_of_email_or_cell errors.add("Either an email address or cell phone number is required") if email.blank? and cell_number.blank? end On Sep 29, 9:34 am, "John T." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Thriving K. wrote: > > Mukund wrote: > >> Write your own validate routine instead of using the helpers. > > >> On Sep 29, 11:32 am, "Thriving K." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > > Is there any guideline for that... please. > > www.google.com > -- > Posted viahttp://www.ruby-forum.com/.