dongri / phonenumber

With a given country and phone number, validate and format the MOBILE phone number to E.164 standard
MIT License
186 stars 46 forks source link

Inconsistent (?) UK Mobile Number Parsing #49

Open jspc opened 3 weeks ago

jspc commented 3 weeks ago

Hey,

Firstly: thank you for this package; it's saved me a lot of work, and I'm very grateful for it.

I'm having a similar issue to https://github.com/dongri/phonenumber/issues/45

Given the UK Mobile Number 07700 900000 (I've sourced this from here, so I'm confident I'm not about to leak somebody's phone number) in three formats:

  1. +44 07700900000 (technically erroneous- the 0 at the start should be omitted when the country code is added, but it's a common format and recognised by every phone I've tested on today)
  2. 07700900000 (as dialled from within the UK)
  3. 447700900000 (an e.164 taken from a SIP header sent by an asterisk system)

I'd expect either the same result from Parse, or for the first example to fail because it's incorrect. What actually happens is examples 2 and 3 succeed, but the first returns 4407700900000 - which is not a valid E.164 phone number.

You can see this in action on the playground: https://go.dev/play/p/bGUGdqLNY0C

Am I doing something wrong? I'm happy to open a PR, but I want to make sure there's not already a solution.

dongri commented 3 weeks ago

@jspc Thank you for your report. I've created a pull request with the following modifications. Could you please review it? https://github.com/dongri/phonenumber/pull/50/files