Change the format of a phone number in the style of a faker

Is there a way to control the phone number format created by faker?

When i call:

Faker::PhoneNumber.cell_phone.to_i 

I get the wrong value.

I also do not want to have an extension.

+6
source share
2 answers

You can customize the format on the fly as follows:

 Faker::Base.numerify('+90(###) ### ####') 

This will solve your problem.

+12
source

Faker::PhoneNumber.cell_phone basically just calls numerify with one of the predefined phone_number_formats .

So you can just use numerify in your own format. E.g. If you want 10 digits, you would do:

 Faker.numerify('#########') 

If you still want to use Faker::PhoneNumber.cell_phone but want to get rid of hyphens, you can use gsub to replace the hyphen like:

 Faker::PhoneNumber.cell_phone.gsub(/-/, '') 
+3
source

All Articles