faker-ruby / faker

A library for generating fake data such as names, addresses, and phone numbers.
MIT License
11.27k stars 3.18k forks source link

Generated phone numbers dont seem to be valid. #1010

Closed dARKaRK closed 7 years ago

dARKaRK commented 7 years ago

I've used Phonelib gem to validate phone number in my models. When I use Faker::PhoneNumber.phone_number for phone numbers during seed data creation, they don't pass the validation. One such example is below:

Faker::PhoneNumber.phone_number
 => "1-451-239-5425 x92803"
p = Phonelib.parse "1-451-239-5425 x92803"
 => #<Phonelib::Phone:0x000000135a3b70 @original="1-451-239-5425 x92803", @extension="", @sanitized="1451239542592803", @original_s="1-451-239-5425 x92803", @data={}, @national_number="1451239542592803">
p.valid?
 => false

I guess the whole point of Faker is to generate fake random things but is there any workaround for models with such validation?

stympy commented 7 years ago

You can either set Phonelib.extension_separator or Phonelib.extension_separate_symbols to use the "x" that Faker returns, or you can override the locale in Faker to change how the extension is returned.