Open ispringle opened 1 year ago
Thank you for your feature proposal.
We marked it as "waiting for user interest" for now to gather some feedback from our community:
If you would like to see this feature be implemented, please react to the description with an up-vote (:+1:).
If you have a suggestion or want to point out some special cases that need to be considered, please leave a comment, so we are aware about them.
We would also like to hear about other community members' use cases for the feature to give us a better understanding of their potential implicit or explicit requirements.
We will start the implementation based on:
the number of votes (:+1:) and comments
the relevance for the ecosystem
availability of alternatives and workarounds
and the complexity of the requested feature
We do this because:
There are plenty of languages/countries out there and we would like to ensure that every method can cover all or almost all of them.
Every feature we add to faker has "costs" associated to it:
For this we would have to decide whether we want to go for fake or regex patterns.
https://github.com/faker-js/faker/blob/next/src/locales/en/phone_number/formats.ts it seems we are already using the !
character in the patterns to ensure the area and branch don't start with 1s? So the main change would be to ensure the numbers also can't end with 11?
Sorry this took so long for me to get back to...
I was not aware of the !
that would take care of the leading digit in the two triplets. I guess then we'd need some way of signifying "not two 1s in a row" (?!11)
.
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:
There are three parts to a +1 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.
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