I'm trying to setup a contact_phone column in my Client model as an integer data type. I would still like to be able to allow users to enter phone numbers in whatever format they like (i.e. 999-999-9999 or 999.999.9999) and just strip out any non-numeric characters before validating it as a valid phone number.
Unfortunately, Rails doesn't seem to want to allow me to run a gsub on the data before validation because it's a FixNum datatype. Does this mean that I have to make it a string in the database to allow users to input non-numeric characters before validation?
My Client Model:
before_validation :strip_contact_phone protected def strip_contact_phone self.contact_phone = self.contact_phone.gsub(/[^0-9]/, '') end
And the resulting error when trying to save a new client:
undefined method `gsub' for 646:Fixnum