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.77k stars 217 forks source link

Mobile number in Jersey not validated as GB number #241

Closed phil-warner closed 6 years ago

phil-warner commented 6 years ago

We've noticed that a valid Jersey Telecom number is parsed successfully as a GB telephone number, but testing it against isValidNumber returns false. The number starts +447797.

catamphetamine commented 6 years ago

See the bug reporting section of the readme. Reopen if required.

phil-warner commented 6 years ago

Sorry. Here is the expected behaviour from the Google libphonenumber page:

https://libphonenumber.appspot.com/phonenumberparser?number=447797732133&country=GB

catamphetamine commented 6 years ago

What does libphonenumber-js demo say and what is the expected outcome.

phil-warner commented 6 years ago

Thanks for the quick reply. The expected outcome is that isValidNumber returns true. libphonenumber-js as you type demo says that it is true, but v1.4.2 when used says it's false. What could be wrong?

catamphetamine commented 6 years ago

Post the exact output of the exact code and the expected output.

phil-warner commented 6 years ago

This is the gist I use in RunKit - https://npm.runkit.com/libphonenumber-js. RunKit is using v1.4.1:

var libphonenumberJs = require("libphonenumber-js");
var destinations = ['447797732133'];

var cleanDestination = function(destination) {

      var destStr = new String(destination);
      // remove all the whitespace
      destStr = destStr.replace(/ /g,'');

      // remove leading +
      if(destStr.substr(0,1) === "+") {
        destStr = destStr.substr(1,destStr.length-1);
      }

      // remove leading 00
      if(destStr.substr(0,2) === "00") {
        destStr = destStr.substr(2,destStr.length-1);
      }

      // remove leading 44
      if(destStr.substr(0,2) === "44") {
        destStr = destStr.substr(2,destStr.length-1);
      }

      return destStr;

    };

var parseGB = function(destination) {
    var parsedGB = libphonenumberJs.parse(destination, 'GB');
    var isValidGB = libphonenumberJs.isValidNumber(parsedGB.phone, 'GB');
    console.log(parsedGB);
    console.log(libphonenumberJs.isValidNumber('7797732133', 'GB'));
    if (isValidGB) {
        console.log('valid GB');
    } else {
        destination = '+' + destination;
        if (libphonenumberJs.isValidNumber(destination)) {
            console.log('valid international: '+destination);
        } else {
            // invalid number
            console.log('invalid number: '+destination);
        }
    }
}

for(var i=0;i<=destinations.length;i++) {
    parseGB(cleanDestination(destinations[i]));
}

It matches the code I use in my application exactly. In my application isValidGB returns false.

catamphetamine commented 6 years ago

Post a minimal code sample and highlight it appropriately.

phil-warner commented 6 years ago

var parsedGB = libphonenumberJs.parse(destination, 'GB'); var isValidGB = libphonenumberJs.isValidNumber(parsedGB.phone, 'GB');

where 'destination' is the number in question - 447797732133

catamphetamine commented 6 years ago

Substitute the phone number to simplify the example. And highlight the code appropriately.

phil-warner commented 6 years ago

This should be adequate for you to try to reproduce it.

catamphetamine commented 6 years ago

You're a very lazy, uneducated, ignoramus, arrogant and selfish man. You deserve your code not working. Leave this job to the ones capable of actually doing things.

iSuslov commented 1 year ago

Wow, I've never seen such a character on GitHub🤦