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

Add the ability to fake Phone numbers that follow the North American Numbering Plan #2550

Closed
calvinballing opened this issue Aug 30, 2022 · 7 comments

Comments

@calvinballing
Copy link
Contributor

Is your feature request related to a problem? Please describe it.
When using Faker with a validator that checks whether numbers follow the North American Numbering Plan (NANP), Faker can provide invalid inputs, as Faker can supply a 1 or 0 for the first and fourth digits which are invalid in the NANP.

For information about the North American Numbering Plan, see:

The NANP numbering format may be summarized in the ten-digit notation NXX NXX-XXXX, where digits N denote any of 2–9, and X is any digit (0–9).

https://en.wikipedia.org/wiki/North_American_Numbering_Plan#Modern_plan

Describe alternatives you've considered
The current workaround is to hard-code a phone number, or compose a valid number using https://github.com/faker-ruby/faker/blob/master/doc/default/number.md

Two options might be:
Add a North-America specific phone number generator that follows the NANP
Add a North-America specific method to the existing phone number generator that follows the NANP

@stefannibrasil
Copy link
Contributor

hi @calvinballing thank you for the details. Are you still able to reproduce this scenario after adding the following configuration?

# For the 'US only' methods below, first you must do the following:
Faker::Config.locale = 'en-US'

There is a reproduction step template available.

@calvinballing
Copy link
Contributor Author

Ah, great, looks like you already have what I was looking for. Thanks!

@stefannibrasil
Copy link
Contributor

that's awesome to hear, @calvinballing I'm curious to know -- if you're interested in sharing: what did you search for? I'm wondering if we could improve the docs to make this feature easier to find.

@calvinballing
Copy link
Contributor Author

@stefannibrasil I looked at: https://github.com/faker-ruby/faker/blob/master/doc/default/phone_number.md

While I had seen that there was an en-US locale option, # For the 'US only' methods below, first you must do the following: had led me to believe that the purpose of the locale option was to be able to use area_code and exchange_code, which I don't need. I didn't realize it would also actually make your number US-like, since I didn't see that mentioned anywhere in the phone number docs.

@stefannibrasil
Copy link
Contributor

@calvinballing that comment is indeed misleading. Are you up to submit a PR clarifying this feature?

@gisellec60
Copy link

gisellec60 commented Sep 20, 2023

Hi - I'm just wondering how to use this. I'm trying to seed a database with only US style numbers. What steps do I need to take? Is there a library I need to include?

@calvinballing
Copy link
Contributor Author

What steps do I need to take? Is there a library I need to include?

For US numbers you need to set:
Faker::Config.locale = 'en-US'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants