🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

phonofy

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phonofy

0.2.0
Rubygems
Version published
Maintainers
1
Created
Source

Phonofy

Phonofy is a Ruby gem that simplifies phone number formatting in Ruby applications using the Phonelib library. It integrates seamlessly with Rails applications (compatible with Rails 6.0 through 8.0) but can also be used in non-Rails environments. With Phonofy, you can easily parse and format phone number data according to international standards, ensuring that your phone number data is consistent and valid across your application.

Installation

Add this line to your application's Gemfile:

gem 'phonofy'

And then execute:

bundle

Or install it yourself as:

gem install phonofy

Usage

To use phonofy, simply call the phonofy method in your Rails model:

class User < ApplicationRecord
  phonofy
end

This will add phone number validation and formatting to the phone_number attribute of the User model.

You can also specify a custom attribute name for the phone number:

class Contact < ApplicationRecord
  phonofy :mobile_number
end

This will add phone number validation and formatting to the mobile_number attribute of the Contact model.

You can also pass additional options to phonofy to customize its behavior:

class User < ApplicationRecord
  phonofy :phone, phonelib: { countries: [:us, :ca], types: [:mobile] }
end

This will add phone number validation and formatting to the phone attribute of the User model, and restrict it to US and Canada mobile phone numbers.

Configuration

You can configure phonofy by creating an initializer file in your Rails application and setting the default options:

# config/initializers/phonofy.rb
Phonofy.configure do |config|
  config.default_phonelib_options = { countries: [:us, :ca], types: [:mobile] }
end

This will set the default options for phonofy to validate only US and Canada mobile phone numbers using the Phonelib library.

International Phone Number Support

Phonofy supports international phone numbers through the Phonelib gem. You can validate and format phone numbers for specific countries by including the country codes in the countries option:

class User < ApplicationRecord
  phonofy :phone, phonelib: { countries: [:us, :gb, :fr] }
end

Example usage:

user = User.new(phone: "+14155552671")
user.phone(:e164)          # => "+14155552671"
user.phone(:international) # => "+1 415-555-2671"
user.phone(:national)      # => "(415) 555-2671"
user.phone_is_valid?       # => true

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/shqear93/phonofy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Credits

phonofy was created by Khaled AbuShqear and is maintained by a community of contributors.

FAQs

Package last updated on 23 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

OSZAR »