I’m trying to create a validation that enforce the :phone field to be 9 digit long if the current object has country_code set to ES.
Im trying to do something like this but it doesn’t work.
validates_length_of :phone, :is => 9, :message => "number needs to be at least 9 digits." if self.country_code == "ES"
I think what you are looking for is:
Or
Take a look at the docs here.