Generating fake phone numbers that are valid based on libphonenumber's rules
Asked Answered
J

0

8

I'd like to use libphonenumber to validate phone numbers, but a number of our integration tests are using Faker to generate test data, and the numbers that this generates are not always valid based on the full validation rules defined in libphonenumber

Is there any way we can use libphonenumber to generate a random set of valid phone numbers? I'm aware of getExampleNumber but this isn't suitable as it only returns a single number of a given type.

Jubilee answered 25/11, 2020 at 9:48 Comment(2)
I was looking for something like this too. I ended up just generating valid phone numbers by generating a valid (real) zip code, then '555' for the 3 digit section, and then a random 4 digit sequence.Eaddy
here is my solution https://mcmap.net/q/1474052/-python-how-to-generate-a-random-phone-numberIncorporeity

© 2022 - 2024 — McMap. All rights reserved.