You're probably thinking this has been asked a million times before but I think that my question is a little different. Most requests for phone number validation are used for validating user input. In my scenario I'm trying to validating incoming phone calls to a US mobile phone, and determine whether they're calling from another country or from within the US.
My main problem is that I'm based in the UK and have no experience of US phone numbers.. I've read about the format of how to dial etc (both international and national) but my worry is that the phone numbers appear differently on the recipient's phone, and in a variety of formats.
Here is the specification of what I'm trying to do..
I'm trying to write the code in PHP and avoid regular expressions. I'm thinking it could use substr() to break down parts of the number.
Any thoughts on how to go about this, code snippets or example phone numbers? I'm really hoping someone from the US will be able to enlighten me on phone number formatting etc..
The people saying to just look for +1 have not worked with telephone numbers much. The 1 country code applies to many areas of North America not just the US. So what really needs to happen is some logic around the tables listed for the North American Numbering Plan and at the List of North American Numbering Plan area codes
Here is a short list of some "exceptional" countries that have numbers starting in +1 that are not US based.
Bermuda:
- After 1995: +1 441 (xxx) xxxx
Puerto Rico:
- After 2001: +1 787 xxx xxxx or +1 939 xxx xxxx (overlay for entire island)
US Virgin Islands:
- After 1997: +1 340 xxx xxxx
Northern Marianas:
- After 1997: +1 670 xxx xxxx
Guam:
- After 1997: +1 671 xxx xxxx
American Samoa:
- After October 2, 2004: +1 684 xxx xxxx
Saint Maarten:
- After joining NANP: +1 721 xxx xxxx (date to be determined)