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
-
Parsing auto-detects as Guernsey: PhoneNumber.parse('+447911123456') returns isoCode: IsoCode.GG instead of IsoCode.GB
-
GB landlines work correctly:
final landline = PhoneNumber(isoCode: IsoCode.GB, nsn: '2071234567'); // London
print(landline.isValid(type: PhoneNumberType.fixedLine)); // true
- 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.
Description
When constructing a
PhoneNumberwithIsoCode.GB(Great Britain/United Kingdom) and a valid UK mobile NSN, validation incorrectly returnsfalse. However, the same number validates correctly when usingIsoCode.GG(Guernsey).Steps to Reproduce
Additional Observations
Parsing auto-detects as Guernsey:
PhoneNumber.parse('+447911123456')returnsisoCode: IsoCode.GGinstead ofIsoCode.GBGB landlines work correctly:
Expected Behavior
PhoneNumber(isoCode: IsoCode.GB, nsn: '7911123456').isValid(type: PhoneNumberType.mobile)should returntruefor valid UK mobile numbers.UK mobile numbers start with
7after the country code (domestic format:07XXX XXXXXX).Environment
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.GGfor validation whenIsoCode.GBis selected and the number starts with7.