Validates_format_of :message not working, validates_length_of :message is working

I’m using validates_format_of and the validation I want to do works, but
can’t get an error message to be displayed if the data is invalid:
validates_format_of :mobile, :with => /\A[+0-9]+\Z/, :message => " -

I have another validation some where else that does display the error
message: " - Name is too long"
validates_length_of :name, :within => 5…40, :too_long => " - Name is

validates_length_of :name, :within => 1…50, :message => “Broken”
This also works but not for validates_format_of

Any ideas?

On 14 August 2012 13:31, tomkins [email protected] wrote:

This also works but not for validates_format_of
You say that you have an example of validates_length_of “somewhere
else” that /does/ work. Are you sure that it is not the “somewhere
else” that is significant. Try replacing the validates_length_of that
is working with a validates_format_of and see if you then get the
message. Also try replacing the format validation that does not show
the error with a validates_length_of.


I tried what you suggested and I got the error message with
validates_format_of where validates_length_of worked, and length_of
work where my format_of wasn’t working. So it looks like the “somwhere
else” is significant, but I cant see any obvious differences between the
two models, any suggestions?

Thanks for the help Colin.

I fixed it, I was missing an tag in my edit code for
page that was not working.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs