DiUS / java-faker

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

en-US locale incorrectly includes Canadian area code 226 #698

Open csyager opened 2 years ago

csyager commented 2 years ago

Describe the bug The en-US locale en-US.faker.phone_number.area_code array (see src/main/resources/en-US.yml, line 41022) includes area code 226, which is a Canadian area code. Phone numbers generated by java-faker with this area code will not pass validation checks asserting that they are valid US numbers.

To Reproduce Since these are randomly generated phone numbers, reproducing this issue is difficult. However using a phone number with this area code that java-faker could generate, for example +12262011212, and Google's libphonenumber, you can demonstrate that this number does not pass validation. See example in Kotlin below:

fun validatePhoneNumber() {
    val phoneNumber = "+12262011212"
    val phoneUtil = PhoneNumberUtil.getInstance()
    val proto = phoneUtil.parse(phoneNumber, "US")
    println(phoneUtil.isValidNumberForRegion(proto, "US"))
}
Output:  false

Running this function with a phone number of +12252011212, which has the valid area code 225, instead prints true.

Expected behavior When set with the en-US locale, java-faker should not generate phone numbers with area code 226, as they are not valid US numbers.

Versions:

Additional context faker-ruby/faker had this same issue and resolved it in May 2021: https://github.com/faker-ruby/faker/issues/2321

The North American Numbering Plan Administration, who sets the area codes, has this list published on their website, which lists 226 as an area code for Ontario.

bodiam commented 2 years ago

@csyager thanks for letting me know. I've fixed it Datafaker here (https://github.com/datafaker-net/datafaker/commit/8d12a6a700215e4925d5fa6d255d18646123297e#diff-34e7864f8f8fc27d914377b08ad3b1fc2feb7d9496beae7e3ce7886f2d535332), along with a few other issues which were fixed in faker-ruby, and I've fixed a few more telephone issues on the way. Thanks for the Kotlin code sample, that was very helpful!