Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

en_GB (UK) phone numbers are sometimes invalid #558

Open
rd-waymark opened this issue Aug 15, 2024 · 2 comments
Open

en_GB (UK) phone numbers are sometimes invalid #558

rd-waymark opened this issue Aug 15, 2024 · 2 comments

Comments

@rd-waymark
Copy link

Bogus NuGet Package

35.6.0

.NET Version

NET 8.0.400

Visual Studio Version

Rider 2024.1.4

What operating system are you using?

Windows

What locale are you using with Bogus?

en_GB

Problem Description

Some phone numbers generated by Faker.Phone.PhoneNumber() when using the en_GB locale are invalid

LINQPad Example or Reproduction Steps

  • Bogus 35.6.0
  • libphonenumber-csharp 8.13.43
using Bogus;
using PhoneNumbers;

void Main()
{
    while(true)
    {
        var faker = new Faker("en_GB");
        
        string phoneNumber = faker.Phone.PhoneNumber();
        
        PhoneNumberUtil? phoneNumberUtil = PhoneNumberUtil.GetInstance();
        PhoneNumbers.PhoneNumber? parsedPhoneNumber = phoneNumberUtil.Parse(phoneNumber, "GB");
        
        if (!phoneNumberUtil.IsValidNumberForRegion(parsedPhoneNumber, "GB"))
        {
            throw new Exception("Invalid phone number " + phoneNumber);
        }
    }
}

Expected Behavior

All UK phone numbers generated by faker.Phone.PhoneNumber(); should be valid.

See Google's libPhoneNumber: https://github.com/google/libphonenumber/blob/master/resources/PhoneNumberMetadata.xml#L11093

Actual Behavior

faker.Phone.PhoneNumber(); sometimes generates invalid UK phone numbers, such as:

  • 016977 0004
  • 0961 296 3851
  • 016977 8550
  • 0887 603 2383

Known Workarounds

Faker.Phone.PhoneNumber("07#########") is a suitable workaround.

Could you help with a pull-request?

No

@Dan-613
Copy link

Dan-613 commented Nov 8, 2024

I can see that the 016977 numbers are incorrect. But what is wrong with the 0887 and 0971 numbers? They appear to be the correct number of digits.

@Dan-613
Copy link

Dan-613 commented Nov 8, 2024

Ignore my previous comments. As Bogus imports its locales directly from faker.js, the issue is with the locale data that faker.js has.

See https://github.com/faker-js/faker/blob/next/src/locales/en_GB/phone_number/format/human.ts

I suggest opening an issue in the faker-js repo. Once resolved, it should get synced into Bogus according to the documentation here https://github.com/bchavez/Bogus/wiki/Creating-Locales

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants