Project

numero

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Numero: Phone number validation for Ruby/Rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

Numero

This tiny gem contains helpers for validating North American phone numbers.

Add it to your Gemfile, or install as a plugin.

Usage

Ruby:

Numero.valid_number?('15554442222') #=> true
Numero.valid_number?('194512') #=> false

Rails:

class User < ActiveRecord::Base
  acts_as_numero :number
end

u = User.new(:number => '1234')
u.valid? #=> false

The North American Numbering Plan

Numero validates phone numbers based on the North American Numbering Plan.

The NANP breaks phone numbers into 4 components:

|A| B | C | D |
+1-555-444-2222

A. ITU country code
B. NPA  - area code
C. NXX  - Central Office code (exchange)
D. XXXX - Subscriber Number

Each section allows for a specific set of numbers:

  • ITU: This is always +1 for North American numbers, although, it is most often written without the +.
  • NPA: First digit must be in the range [2-9], second and third digit can be any number [0-9].
  • NXX: First digit must be in the range [2-9], second and third digit can be any number [0-9].
  • XXXX: [0-9] for each digit