Validating phone number in ruby

phone-number, regex, ruby

Solution

There are many gems that will do this for you.

Take a look at: http://rubygems.org/search?utf8=%E2%9C%93&query=phone+number

This one looks like it will do what you need -- it essentially implements a regex to validate the phone number: http://rubygems.org/gems/validates_phone_number

For US, Canada (Bermuda, Bahamas... etc and all +1 numbers) there are other rules that the regex should follow. The first digit (after the +1) must be 2-9.

For a full list see: http://en.wikipedia.org/wiki/North_American_Numbering_Plan

Problem

What are the rules for validating a North American phone number? Also, is there a `regex` I can use? Is there a gem to do this? Here are few rules I have in mind - A 10 digit number - no special characters - A positive number

Original source

Related problems