phonelib

phonelib is an open-source Ruby gem for parsing, formatting, and validating phone numbers using Google's libphonenumber data. MIT licensed with 1,100+ GitHub stars.

Overview

phonelib is a Ruby gem that brings phone number parsing, validation, and formatting capabilities to Ruby applications by leveraging Google's libphonenumber data. It allows developers to validate whether a phone number is possible or valid for a given country, parse raw number strings into structured objects, and format numbers into international or national representations. Because it is built on the same underlying data that Google maintains for libphonenumber, it supports a wide range of countries and carrier formats without requiring a native C extension. The project is actively maintained on GitHub, holds over 1,100 stars, and is released under the permissive MIT license, making it suitable for both commercial and open-source Ruby projects. It integrates naturally with Ruby on Rails applications and is commonly used alongside ActiveRecord validations to ensure phone number data quality at the model layer.

Highlights

  • Parse phone number strings into structured objects with country and national number components
  • Validate whether a number is possible or fully valid for a specific country or region
  • Format parsed numbers in international (E.164) or national notation
  • Built on Google's libphonenumber data for broad international coverage
  • Pure Ruby implementation with no native C extension required
  • MIT licensed and compatible with Ruby on Rails ActiveRecord validations

Common use cases

  • Validating user-submitted phone numbers in Ruby on Rails web applications
  • Normalising and formatting phone numbers before storing them in a database
  • Checking whether a collected number belongs to a specific country or region
  • Sanitising phone number fields in CRM or customer support platforms built with Ruby

View upstream source