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

e164PhoneNumber() generates invalid US Phone Numbers #332

Closed
RPJamie opened this issue Jun 11, 2021 · 4 comments · Fixed by #380
Closed

e164PhoneNumber() generates invalid US Phone Numbers #332

RPJamie opened this issue Jun 11, 2021 · 4 comments · Fixed by #380

Comments

@RPJamie
Copy link

RPJamie commented Jun 11, 2021

Summary

Using e164PhoneNumber(), an invalid number is created for en_US. The generated phone numbers that start with 0 or 1, are invalid.

Versions

Version
PHP 8.0
fakerphp/faker 1.14.1

Self-enclosed code snippet for reproduction

 $faker = FakerFactory::create();

dump($faker->e164PhoneNumber());

Example invalid number that was generated: +16200858074

Tested using giggsey/libphonenumber-for-php library locally as well as the online version
https://giggsey.com/libphonenumber/index.php?phonenumber=%2B16200858074&country=US //Starting with 0
https://giggsey.com/libphonenumber/index.php?phonenumber=%2B16201858074&country=US //Starting with 1

both isValidNumber() and isValidNumberForRegion() fail

@bram-pkg
Copy link
Member

I'm not sure I understand, from my understanding phone numbers can start with a + followed by a country code.

@IonBazan
Copy link

IonBazan commented Jun 11, 2021

@RPJamie @bramceulemans According to Wikipedia, +1 (620) 085-8074 is invalid because 085 is an invalid Central Office code - they may not start with 0 or 1. What is more, the last 2 digits of Central Office code may not be 11. These rules raise the complexity of E164 number faking dramatically and personally I don't think it's worth keeping it 100% compliant but PRs are welcome 😉

@stale
Copy link

stale bot commented Jun 25, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 1 week if no further activity occurs. Thank you for your contributions.

@stale stale bot closed this as completed Jul 2, 2021
@miken32
Copy link

miken32 commented Sep 22, 2021

@IonBazan this is a simple check and anyway the code is already in place. In Faker\Provider\en_US\PhoneNumber simply change the format string to include the exchange code placeholder.

protected static $e164Formats = [
    '+1{{areaCode}}{{exchangeCode}}####',
];

None of the other en_US phone number formatters have this problem, just the e164 one.

Happy to create a PR if needed to fix this one LOC.

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

Successfully merging a pull request may close this issue.

4 participants