DiUS / java-faker

Brings the popular ruby faker gem to Java
http://dius.github.io/java-faker
Other
4.72k stars 844 forks source link

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

Open manueljordan opened 5 years ago

manueljordan commented 5 years ago

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

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

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

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

Therefore something to:

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 commented 5 years ago

@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 commented 5 years ago

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

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 commented 5 years ago

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

Numichi commented 3 years ago

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 commented 3 years ago

You can use a regex directly:

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

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