Kevin wrote:> I am attempting to validate a phone number field to assure that it is
> only 10 digits. I''ve placed the following code in my model:
>
> validates_length_of :phone, :is => 10, :message => "should be 10
> digits.", :allow_nil => true
>
> However, even when 10 digits are entered (with no dashes or parentheses)
> I still receive a validation error.
>
> Any help would be appreciated. Thanks.
put this in your model..
def validate
unless self.phone.to_s.size == 10
errors.add("phone", "should be 10 digits")
end
end
URL => http://theocacao.com/document.page/188
--
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
-~----------~----~----~----~------~----~------~--~---