Description
Clear and concise description of the problem
This won't generate valid and random numbers though. At least not valid US/CA (aka the North American Numbering Plan, or those phones using the country code +1) phone numbers. A +1 number must broadly speaking follow the pattern:
^[2-9](?!11)\d{2}-?[2-9](?!11)\d{2}-?[0-9]{4}$
There are three parts to a +1 number:
- area code
- central office or branch code
- line number
The line number can be any four digits (\d{4}
). The first two triplets (area and branch) cannot start with the number 1 ([2-9]\d{2}
) and they cannot end with the two ones. Currently there is no way (that I can tell) to create valid +1 phone numbers with Faker. I can manually set the area and branch to a fixed number and just generate random line numbers, however for some use cases this is not acceptable (for example determining the area code).
Suggested solution
I have two potential solutions.
- The existing faker.phone.number method could accept a more detailed string. This could be achieved by either allowing for some regex-like pattern to be passed or providing some additional syntax beyond just replacing the pound with a random digit.
- Make the existing
faker.phone.number
output phone numbers that are proper and valid North American Numbering Plan numbers. This seems like the solution more inline with how faker is setup, as to the best of my knowledge most of the defaultfaker
API methods return US formatted data and if you wish to use say a Polish locale you need to import that separately.
Alternative
No response
Additional context
Here is the wikipedia article on the North American Numbering plan: https://en.wikipedia.org/wiki/North_American_Numbering_Plan