phone_number icon indicating copy to clipboard operation
phone_number copied to clipboard

False positive

Open AlexanderFarkas opened this issue 2 years ago • 4 comments


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" Screenshot 2022-06-09 at 16 37 43

For some reason it's parsed as "+12468588888"

AlexanderFarkas avatar Jun 09 '22 09:06 AlexanderFarkas

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 avatar Jun 28 '22 03:06 ooglek

@ooglek is this still a valid issue?

iamsahilsonawane avatar Aug 10 '22 05:08 iamsahilsonawane

maybe if this would be updated to latest from libphonenumber, would fix this issue.

jovanialferez avatar Oct 11 '22 04:10 jovanialferez

Hey @jovanialferez thanks for the suggestion. Will definitely look into this.

iamsahilsonawane avatar Oct 11 '22 12:10 iamsahilsonawane

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

deandreamatias avatar Apr 27 '23 11:04 deandreamatias