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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With