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

Let for the phoneNumber() and cellPhone() methods put a format #380

Open
manueljordan opened this issue Apr 23, 2019 · 5 comments
Open

Let for the phoneNumber() and cellPhone() methods put a format #380

manueljordan opened this issue Apr 23, 2019 · 5 comments

Comments

@manueljordan
Copy link

I am playing a lot with this wonderful library, thanks for this tool

Well, I am working in peace until some point with:

  • faker.phoneNumber().cellPhone()
  • faker.phoneNumber().phoneNumber()

Just curious if I can set the phone number or cell phone format prior to be generated to the following patterns:

  • ###### (possible in someway just with faker.numerify("######"))
  • ##-##-## (possible in someway just with faker.numerify("##-##-##"))

Even better to something like: (mostly I need this)

  • [2-4]#-##-## to get valid just: (22-67-11 * 23-88-99 * 38-20-15 * 43-98-44 )
  • [2-4]##### to get valid just: (226711 * 238899 * 382015 * 439844 )

Therefore something to:

  • faker.phoneNumber().cellPhone([2-4]#-##-##)
  • faker.phoneNumber().phoneNumber([2-4]#####)

Thus I am not sure if is possible (if yes - how can be configured?) and if not, consider add this feature

Thanks for your understanding

@kellerj
Copy link

kellerj commented Apr 25, 2019

@manueljordan You may want to take a look at the data underlying this API. It was not designed for arbitrary digits with a regex-like pattern. I too would like to be able to specify a format, but my need is mainly for delimiter differences.

Take a look at this file in the project: src/main/resources/en-US.yml and search for phone_number

I'm assuming those formats are common to a non-US country. I did not look into the other configuration files in that directory, but maybe you can get what you need by adding to one of the YML files in there.

@manueljordan
Copy link
Author

Hello @kellerj , yes, I saw that file, sadly in my country the patterns numbers change for each city. It about two important things:

  • Size, for my city is maximum 6 digits, in other cities, 7 digits
  • The two first numbers varies according the cities, in my city would start with 23, 44, 25, and in other cities with 66, 65.

And even more, would be: (054)-226711 or (051)-2588769

Thus I need set the length or pattern manually (and restrict the two first digits)

@serhiiperfectial
Copy link

Hi, is there an option to generate fake cellPhone() that will contain country code all the time?

@Numichi
Copy link

Numichi commented Apr 3, 2021

Is this feature support to international phone prefix or numbers? I am thinking here of the plus sign.
https://en.wikipedia.org/wiki/List_of_country_calling_codes

@Breina
Copy link

Breina commented Aug 19, 2021

You can use a regex directly:

Faker.instance().expression("#{regexify '" PHONE_NUMER_REGEX "'}")

I suggest this one: https://phoneregex.com/

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

Successfully merging a pull request may close this issue.

5 participants