Skip to content

IsoCode.GB incorrectly rejects valid UK mobile numbers #108

@tyler-jewell

Description

@tyler-jewell

Description

When constructing a PhoneNumber with IsoCode.GB (Great Britain/United Kingdom) and a valid UK mobile NSN, validation incorrectly returns false. However, the same number validates correctly when using IsoCode.GG (Guernsey).

Steps to Reproduce

import 'package:phone_numbers_parser/phone_numbers_parser.dart';

void main() {
  // UK mobile number: 07911 123456 → NSN is 7911123456
  final gbPhone = PhoneNumber(isoCode: IsoCode.GB, nsn: '7911123456');
  final ggPhone = PhoneNumber(isoCode: IsoCode.GG, nsn: '7911123456');
  
  print('GB: isValid=${gbPhone.isValid()}, isMobile=${gbPhone.isValid(type: PhoneNumberType.mobile)}');
  // Output: GB: isValid=false, isMobile=false
  
  print('GG: isValid=${ggPhone.isValid()}, isMobile=${ggPhone.isValid(type: PhoneNumberType.mobile)}');
  // Output: GG: isValid=true, isMobile=true
}

Additional Observations

  1. Parsing auto-detects as Guernsey: PhoneNumber.parse('+447911123456') returns isoCode: IsoCode.GG instead of IsoCode.GB

  2. GB landlines work correctly:

final landline = PhoneNumber(isoCode: IsoCode.GB, nsn: '2071234567'); // London
print(landline.isValid(type: PhoneNumberType.fixedLine)); // true
  1. Test results summary:
IsoCode UK Mobile (7911123456) UK Landline (2071234567)
GB ❌ invalid ✅ valid
GG ✅ valid ❌ invalid

Expected Behavior

PhoneNumber(isoCode: IsoCode.GB, nsn: '7911123456').isValid(type: PhoneNumberType.mobile) should return true for valid UK mobile numbers.

UK mobile numbers start with 7 after the country code (domestic format: 07XXX XXXXXX).

Environment

  • phone_numbers_parser: 9.0.18
  • Dart SDK: 3.9.0
  • Flutter: 3.32.1

Impact

This breaks phone number validation in country picker UIs where users select "United Kingdom" and enter their mobile number. The validation fails even though the number is valid.

Workaround

Currently working around this by using IsoCode.GG for validation when IsoCode.GB is selected and the number starts with 7.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions