kevin
1
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.
kevin
2
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 => Theocacao: Rails validates_length_of and Fixnum