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

Missing phone number types #68

Closed
cottonman132 opened this issue May 28, 2024 · 5 comments · Fixed by #70
Closed

Missing phone number types #68

cottonman132 opened this issue May 28, 2024 · 5 comments · Fixed by #70

Comments

@cottonman132
Copy link
Contributor

There are some number types which are missing in this library. This causes valid number types to be marked as invalid.

For example, take the US phone number metadata. In this library it is defined by this object:

PhoneMetadataPatterns(
  nationalPrefixForParsing: null,
  nationalPrefixTransformRule: null,
  general: r"[2-9]\d{9}|3\d{6}",
  mobile:
      r"(?:5056(?:[0-35-9]\d|4[468])|7302[01]\d)\d{4}|(?:472[24]|505[2-57-9]|983[289])\d{6}|(?:2(?:0[1-35-9]|1[02-9]|2[03-57-9]|3[149]|4[08]|5[1-46]|6[0279]|7[0269]|8[13])|3(?:0[1-57-9]|1[02-9]|2[013569]|3[0-24679]|4[167]|5[0-2]|6[0149]|8[056])|4(?:0[124-9]|1[02-579]|2[3-5]|3[0245]|4[023578]|58|6[349]|7[0589]|8[04])|5(?:0[1-47-9]|1[0235-8]|20|3[0149]|4[01]|5[179]|6[1-47]|7[0-5]|8[0256])|6(?:0[1-35-9]|1[024-9]|2[03689]|3[016]|4[0156]|5[01679]|6[0-279]|78|8[0-29])|7(?:0[1-46-8]|1[2-9]|2[04-7]|3[1247]|4[037]|5[47]|6[02359]|7[0-59]|8[156])|8(?:0[1-68]|1[02-8]|2[068]|3[0-2589]|4[03578]|5[046-9]|6[02-5]|7[028])|9(?:0[1346-9]|1[02-9]|2[0589]|3[0146-8]|4[01357-9]|5[12469]|7[0-389]|8[04-69]))[2-9]\d{6}",
  fixedLine:
      r"(?:5056(?:[0-35-9]\d|4[468])|7302[01]\d)\d{4}|(?:472[24]|505[2-57-9]|983[289])\d{6}|(?:2(?:0[1-35-9]|1[02-9]|2[03-57-9]|3[149]|4[08]|5[1-46]|6[0279]|7[0269]|8[13])|3(?:0[1-57-9]|1[02-9]|2[013569]|3[0-24679]|4[167]|5[0-2]|6[0149]|8[056])|4(?:0[124-9]|1[02-579]|2[3-5]|3[0245]|4[023578]|58|6[349]|7[0589]|8[04])|5(?:0[1-47-9]|1[0235-8]|20|3[0149]|4[01]|5[179]|6[1-47]|7[0-5]|8[0256])|6(?:0[1-35-9]|1[024-9]|2[03689]|3[016]|4[0156]|5[01679]|6[0-279]|78|8[0-29])|7(?:0[1-46-8]|1[2-9]|2[04-7]|3[1247]|4[037]|5[47]|6[02359]|7[0-59]|8[156])|8(?:0[1-68]|1[02-8]|2[068]|3[0-2589]|4[03578]|5[046-9]|6[02-5]|7[028])|9(?:0[1346-9]|1[02-9]|2[0589]|3[0146-8]|4[01357-9]|5[12469]|7[0-389]|8[04-69]))[2-9]\d{6}",
)

Here we can find there a 2 number types defined.

Now, looking at the metadate for US phone number on iOS' PhoneNumberKit:

{
  "id":"US",
  "mainCountryForCode":"true",
  "countryCode":"1",
  "internationalPrefix":"011",
  "nationalPrefix":"1",
  "mobileNumberPortableRegion":"true",
  "availableFormats":{
    "numberFormat":[
      {
        "pattern":"(\\d{3})(\\d{4})",
        "nationalPrefixOptionalWhenFormatting":"true",
        "leadingDigits":"310",
        "format":"$1-$2"
      },
      {
        "pattern":"(\\d{3})(\\d{4})",
        "leadingDigits":"[24-9]|3(?:[02-9]|1[1-9])",
        "format":"$1-$2",
        "intlFormat":"NA"
      },
      {
        "pattern":"(\\d{3})(\\d{3})(\\d{4})",
        "nationalPrefixOptionalWhenFormatting":"true",
        "leadingDigits":"[2-9]",
        "format":"($1) $2-$3",
        "intlFormat":"$1-$2-$3"
      }
    ]
  },
  "generalDesc":{
    "nationalNumberPattern":"[2-9]\\d{9}|3\\d{6}"
  },
  "fixedLine":{
    "possibleLengths":{
      "national":"10",
      "localOnly":"7"
    },
    "exampleNumber":"2015550123",
    "nationalNumberPattern":"(?:5056(?:[0-35-9]\\d|4[468])|73020\\d)\\d{4}|(?:4722|505[2-57-9]|983[289])\\d{6}|(?:2(?:0[1-35-9]|1[02-9]|2[03-57-9]|3[149]|4[08]|5[1-46]|6[0279]|7[0269]|8[13])|3(?:0[1-57-9]|1[02-9]|2[013569]|3[0-24679]|4[167]|5[0-2]|6[0149]|8[056])|4(?:0[124-9]|1[02-579]|2[3-5]|3[0245]|4[023578]|58|6[349]|7[0589]|8[04])|5(?:0[1-47-9]|1[0235-8]|20|3[0149]|4[01]|5[179]|6[1-47]|7[0-5]|8[0256])|6(?:0[1-35-9]|1[024-9]|2[03689]|[34][016]|5[01679]|6[0-279]|78|8[0-29])|7(?:0[1-46-8]|1[2-9]|2[04-7]|3[1247]|4[037]|5[47]|6[02359]|7[0-59]|8[156])|8(?:0[1-68]|1[02-8]|2[068]|3[0-2589]|4[03578]|5[046-9]|6[02-5]|7[028])|9(?:0[1346-9]|1[02-9]|2[0589]|3[0146-8]|4[01357-9]|5[12469]|7[0-389]|8[04-69]))[2-9]\\d{6}"
  },
  "mobile":{
    "possibleLengths":{
      "national":"10",
      "localOnly":"7"
    },
    "exampleNumber":"2015550123",
    "nationalNumberPattern":"(?:5056(?:[0-35-9]\\d|4[468])|73020\\d)\\d{4}|(?:4722|505[2-57-9]|983[289])\\d{6}|(?:2(?:0[1-35-9]|1[02-9]|2[03-57-9]|3[149]|4[08]|5[1-46]|6[0279]|7[0269]|8[13])|3(?:0[1-57-9]|1[02-9]|2[013569]|3[0-24679]|4[167]|5[0-2]|6[0149]|8[056])|4(?:0[124-9]|1[02-579]|2[3-5]|3[0245]|4[023578]|58|6[349]|7[0589]|8[04])|5(?:0[1-47-9]|1[0235-8]|20|3[0149]|4[01]|5[179]|6[1-47]|7[0-5]|8[0256])|6(?:0[1-35-9]|1[024-9]|2[03689]|[34][016]|5[01679]|6[0-279]|78|8[0-29])|7(?:0[1-46-8]|1[2-9]|2[04-7]|3[1247]|4[037]|5[47]|6[02359]|7[0-59]|8[156])|8(?:0[1-68]|1[02-8]|2[068]|3[0-2589]|4[03578]|5[046-9]|6[02-5]|7[028])|9(?:0[1346-9]|1[02-9]|2[0589]|3[0146-8]|4[01357-9]|5[12469]|7[0-389]|8[04-69]))[2-9]\\d{6}"
  },
  "tollFree":{
    "possibleLengths":{
      "national":"10"
    },
    "exampleNumber":"8002345678",
    "nationalNumberPattern":"8(?:00|33|44|55|66|77|88)[2-9]\\d{6}"
  },
  "premiumRate":{
    "possibleLengths":{
      "national":"10"
    },
    "exampleNumber":"9002345678",
    "nationalNumberPattern":"900[2-9]\\d{6}"
  },
  "personalNumber":{
    "possibleLengths":{
      "national":"10"
    },
    "exampleNumber":"5002345678",
    "nationalNumberPattern":"52(?:3(?:[2-46-9][02-9]\\d|5(?:[02-46-9]\\d|5[0-46-9]))|4(?:[2-478][02-9]\\d|5(?:[034]\\d|2[024-9]|5[0-46-9])|6(?:0[1-9]|[2-9]\\d)|9(?:[05-9]\\d|2[0-5]|49)))\\d{4}|52[34][2-9]1[02-9]\\d{4}|5(?:00|2[125-9]|33|44|66|77|88)[2-9]\\d{6}"
  }
}

We can see there are 3 number formats that are missing in this library: "tollFree", "premiumRate" and "personalNumber".

Due to this, a valid US phone number like 1 800-934-6489 is parsed as an invalid number.

@cedvdb
Copy link
Owner

cedvdb commented May 28, 2024

that's because those number types are currently unsupported, support must be added by the community.

Here is someone adding voip support for reference

#59

@cottonman132
Copy link
Contributor Author

Ok. I'll see about making a PR adding the missing types

@cedvdb
Copy link
Owner

cedvdb commented May 28, 2024

I'd suggest making a first PR for the metadata that converts the original metadata into dart class to add the necessary information, that part should be somewhat straight forward. After that a second PR for the library to use those values. This is going to be much easier to review

@cottonman132
Copy link
Contributor Author

@cedvdb could you update the upstream package with the recent changes?

@cedvdb
Copy link
Owner

cedvdb commented May 29, 2024

available in v8.3.0

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

Successfully merging a pull request may close this issue.

2 participants