faker icon indicating copy to clipboard operation
faker copied to clipboard

Faker.Phone.EnUs.phone() produces invalid phone numbers

Open icecapp opened this issue 4 years ago • 2 comments

This is most likely known/expected, but un(der?)documented.

After investigating why my test suite started sporadically failing, I discovered that Faker.Phone.EnUs.phone() often produces invalid numbers.

to demonstrate:

def test_faker_us_phone_numbers()
    Faker.Phone.EnUs.phone() 
    |> ExPhoneNumber.parse("US")
    |> ExPhoneNumber.is_valid_number?
end
iex(24)> Auth.test_faker_us_phone_numbers()
914/967-0531 is valid: true
iex(25)> Auth.test_faker_us_phone_numbers()
6237465431 is valid: true
iex(26)> Auth.test_faker_us_phone_numbers()
232-341-9001 is valid: false
iex(27)> Auth.test_faker_us_phone_numbers()
368.551.0368 is valid: false
iex(28)> Auth.test_faker_us_phone_numbers()
6063538095 is valid: true
iex(29)> Auth.test_faker_us_phone_numbers()
974.733.0044 is valid: false
iex(30)> Auth.test_faker_us_phone_numbers()
(963) 718-4753 is valid: false
iex(31)> Auth.test_faker_us_phone_numbers()
(949) 625-0125 is valid: true
iex(32)> Auth.test_faker_us_phone_numbers()
253.921.0196 is valid: true

For example, it can produce (963) 718-4753 which will never exist.

I understand maintaining an area code map is work, so perhaps just warning that this can conflict with validation libraries that do keep up-to-date (or try, as even "368" in iex(27) just got added May 2021)

icecapp avatar Jul 16 '21 18:07 icecapp

Hi @icecapp thank you for your bug report. @igas I'd like to take a look at this one.

kristinabrueva avatar Jul 24 '21 09:07 kristinabrueva

Thank you @Bruuu. Your help is much appreciated.

igas avatar Jul 24 '21 09:07 igas