Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support random and valid North American Numbering Plan phone numbers #2303

Open
ispringle opened this issue Aug 9, 2023 · 4 comments
Open
Labels
c: feature Request for new feature m: phone Something is referring to the phone module p: 1-normal Nothing urgent s: waiting for user interest Waiting for more users interested in this feature
Milestone

Comments

@ispringle
Copy link

Clear and concise description of the problem

https://fakerjs.dev/api/phone.html#number

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:

  1. area code
  2. central office or branch code
  3. 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.

  1. 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.
  2. 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 default faker 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

@ispringle ispringle added c: feature Request for new feature s: pending triage Pending Triage s: waiting for user interest Waiting for more users interested in this feature labels Aug 9, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 9, 2023

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:
    • initial costs: design, implementation, reviews, documentation
    • running costs: awareness of the feature itself, more complex module structure, increased bundle size, more work during refactors

View more issues which are waiting for user interest

@ST-DDT ST-DDT added p: 1-normal Nothing urgent m: phone Something is referring to the phone module and removed s: pending triage Pending Triage labels Aug 9, 2023
@ST-DDT ST-DDT added this to the vFuture milestone Aug 9, 2023
@ST-DDT
Copy link
Member

ST-DDT commented Aug 9, 2023

For this we would have to decide whether we want to go for fake or regex patterns.

@matthewmayer
Copy link
Contributor

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?

@ispringle
Copy link
Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: feature Request for new feature m: phone Something is referring to the phone module p: 1-normal Nothing urgent s: waiting for user interest Waiting for more users interested in this feature
Projects
None yet
Development

No branches or pull requests

3 participants