This gem creates a new field type ‘Mongoid::PhoneNumber’ for mongoid. It discards all non-numeric parts of the phone number while storing in database and prints out the well formatted phone number when retrieved. Currently it supports only north-american phone number format.
gem install mongoid_phone_number
class User include Mongoid::Document field :home_phone, :type => Mongoid::PhoneNumber end
user.home_phone = '1 (809) (123) (1234)' user.home_phone = '18091231234' user.home_phone = '+1-809-123-1234' ...
user.home_phone # "1-809-123-1234" user.home_phone = '809 123 1234' user.home_phone # '809-123-1234'
Copyright © 2011 Sarwagya Pandey. See LICENSE.txt for further details.