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 I can’t get an error message to be displayed if the data is invalid:

validates_format_of :mobile, :with => /\A[+0-9]+\Z/, :message => " - Wrong"

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 too long",

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

Any ideas?


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 didn’t 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 the page that was not working.