catamphetamine / libphonenumber-js

A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript
https://catamphetamine.gitlab.io/libphonenumber-js/
MIT License
2.76k stars 218 forks source link

Australian 13-numbers do not get correctly formatted. #400

Open ccg-tim opened 3 years ago

ccg-tim commented 3 years ago

In Australia, 13-smart numbers (different from 1300 numbers, as 13-numbers are 6 digits long) do not correctly get formatted using the AsYouType formatter.

According to the Australian style guide (https://www.stylemanual.gov.au/style-rules-and-conventions/numbers-and-measurements/telephone-numbers) 6 digit 13 numbers should be written like this:

13 33 45

Using the AsYouTypeFormatter from the Google Demo, it gets rendered correctly.

Using libphonenumber-js, it gets rendered as

133345

Google's demo link

https://libphonenumber.appspot.com/phonenumberparser?number=134578&country=AU

Screen Shot 2021-05-26 at 4 07 33 pm Screen Shot 2021-05-26 at 4 07 22 pm Screen Shot 2021-05-26 at 4 07 40 pm

ccg-tim commented 3 years ago

Note, this has already been reported on issue #297, however, it is important to note that the number format that was shown was for Premium rate SMS - but this issue is not a premium rate SMS number. As shown in the screenshot, it is a SHARED_COST number, similar to 1300-numbers.

Smartnumbers® are 13, 1300 or 1800 telephone numbers. Smartnumbers® include phonewords like 13 CATS (13 2287) and distinctive patterned numbers such as 1300 222 222.

https://www.thenumberingsystem.com.au/

Smartnumbers are catchy numbers. They might:

  • be in a pattern, such as 1300 456 789
  • have double digits, such as 1300 222 222

https://www.acma.gov.au/buy-custom-number

https://github.com/google/libphonenumber/blob/c6277266fba8223cfc610cfb1e999deb9f876d65/resources/PhoneNumberMetadata.xml#L2528-L2541

      <!-- Local-rate (SmartNumbers) are put here because they are a reverse-charge network,
           although they charge a small local call connect fee (around 25c). These start with 13
           or 1300. -->
      <sharedCost>
        <possibleLengths national="6,8,10"/>
        <exampleNumber>1300123456</exampleNumber>
        <nationalNumberPattern>
          13(?:
            00\d{3}|
            45[0-4]
          )\d{3}|
          13\d{4}
        </nationalNumberPattern>
      </sharedCost>

https://github.com/google/libphonenumber/blob/c6277266fba8223cfc610cfb1e999deb9f876d65/resources/PhoneNumberMetadata.xml#L2335-L2340

          <!-- 6-digit variable cost fixed line (toll free, premium rate, shared cost) -->
        <numberFormat pattern="(\d{2})(\d{2})(\d{2})">
          <leadingDigits>13</leadingDigits>
          <format>$1 $2 $3</format>
          <intlFormat>NA</intlFormat>
        </numberFormat>
catamphetamine commented 3 years ago

Hi. Thanks for the detailed report 👍. It does help having such details when issues are reported.

I have changed the README description previously to remove the seemingly too complex note about the library not formatting phone numbers with area code omitted: https://raw.githubusercontent.com/catamphetamine/libphonenumber-js/master/README.md

Looks like I should re-add it because you're the first one who has reported something like this, and it happened after I've removed that note.

Don't close this issue though because it will be something that others could see. I'll update the README on GitLab and on GitHub. The NPM readme will be updated on next package release.

ccg-tim commented 3 years ago

No worries, happy to help :)

This is not a number without an area code. Similar to the 1300 number (https://libphonenumber.appspot.com/phonenumberparser?number=1300555444&country=AU) which does get formatted correctly, the 13 number works in all areas of Australia.

Here is an Aussie ad for good measure :) https://www.youtube.com/watch?v=Y0HchzE-7rM

catamphetamine commented 3 years ago

Here is an Aussie ad for good measure

Cool )

So, to conclude, in Australia there're "mobile" numbers and "landline" numbers (like in any other country). "Landline" numbers can be written in:

Source: https://www.stylemanual.gov.au/style-rules-and-conventions/numbers-and-measurements/telephone-numbers

So, considering that this library is made for inputting people's personal phone numbers (mostly mobile) and not for crawling the web for all possible numbers (like Google's library), it doesn't have to format ads numbers because people shouldn't input those in the input field

And if they've bought a fancy shortened number for themselves then they'd have to input a regular number just like all other normal people do. They're no "special", are they.

So we don't consider this a bug, rather a feature.

I've updated the readme note to include a link to this issue.

catamphetamine commented 3 years ago

@ccg-tim Lube Mobile will come to you, just for $300

sss