class Product < ActiveRecord::Base
validates_format_of :hs_class_code, :with =>
self.hs_class_code.gsub!(".","") unless self.hs_class_code.nil?
It makes it more clear if you name the method. Also, it is a good idea to use self. to be sure that what are intended to be accessor method calls are not interpreted as local variables.
Another problem was the use of tr which returns nil if no substitution is made. The was your initial method was written, if hs_class_code did not contain the "." character, the result would be to call strip on nil.
Hope this helps
James Byrne wrote: