phone_number
phone_number copied to clipboard
False positive
Future<bool> _validatePhone(String? value) async {
if (value == null) return false;
try {
final plugin = PhoneNumberUtil();
if (!value.startsWith("+")) {
value = "+1$value";
}
final phoneNumber = await plugin.parse(value, regionCode: "US");
final regions =
await plugin.allSupportedRegions();
String regionCode;
try {
regionCode = regions
.firstWhere(
(element) =>
element.prefix == int.tryParse(phoneNumber.countryCode),
)
.code;
} on StateError {
regionCode = 'US';
}
return await plugin.validate(value, regionCode);
} catch (e) {
return false;
}
}
This code returns True for number "+18588888"
For some reason it's parsed as "+12468588888"
I'm having a similar albeit opposite issue with +1 314 246 xxxx -- using phone_number 0.12.0+2
The number is valid on the libphonenumber test website.
{
countryCode: 1,
e164: +13142467446,
national: (314) 246-7446,
type: PhoneNumberType.FIXED_LINE_OR_MOBILE,
international: +1 314-246-7446,
nationalNumber: 3142467446
}
I/flutter ( 8650): valid: false
@ooglek is this still a valid issue?
maybe if this would be updated to latest from libphonenumber
, would fix this issue.
Hey @jovanialferez thanks for the suggestion. Will definitely look into this.
Now with the last version of libphonenumber, this issue will be solved I guess. If happens again, please reopen this issue or create a new one