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

Are there plans to support generating international phone numbers? #160

Open
qrilka opened this issue Dec 11, 2023 · 4 comments
Open

Are there plans to support generating international phone numbers? #160

qrilka opened this issue Dec 11, 2023 · 4 comments

Comments

@qrilka
Copy link

qrilka commented Dec 11, 2023

From the code it looks like the crate only supports generating just US local phone numbers. The docs don't tell much about the supported formats BTW.

@cksac
Copy link
Owner

cksac commented Dec 13, 2023

each locale can overwrite default phone number format when impl the Data trait
https://github.com/cksac/fake-rs/blob/master/fake/src/locales/ja_jp.rs#L392
if not overwrite, it will use US format.

you can also use NumberWithFormat<'a>(fmt: &'a str); to generate any phone number

// ^: 1-9, #: 0-9

@qrilka
Copy link
Author

qrilka commented Dec 13, 2023

Thanks, I saw those formats but they are for local numbers. I was searching for something like https://github.com/faker-ruby/faker/blob/main/doc/default/phone_number.md#fakerphonenumberphone_number_with_country_code

@srfsh
Copy link

srfsh commented Sep 27, 2024

I second that we need a utility function. I design my API endpoints to always use E164 formats. I would think most folks do this as well. After all, the UI generally takes care of these sorts of cleansing the input data, otherwise you'd need to sync parsing logic between the API and the UI.

@srfsh
Copy link

srfsh commented Sep 29, 2024

I second that we need a utility function. I design my API endpoints to always use E164 formats. I would think most folks do this as well. After all, the UI generally takes care of these sorts of cleansing the input data, otherwise you'd need to sync parsing logic between the API and the UI.

I tacked this a little bit in my free time, and I think this can't be done with a locale, or shouldn't be. You see, the locales are specific to a region. Thus, the numbers are restricted to, say, a country. But E164-formatted numbers are generally international, and can belong to any region. Further more, you can't easily generate them with # or ^ since each country has a different format for numbers. This is what makes this problem difficult. A work around is to just stick to NumberWithFormat with a fixed formatting, which is suboptimal, I know.

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

No branches or pull requests

3 participants