Closed phil-warner closed 6 years ago
See the bug reporting section of the readme. Reopen if required.
Sorry. Here is the expected behaviour from the Google libphonenumber page:
https://libphonenumber.appspot.com/phonenumberparser?number=447797732133&country=GB
What does libphonenumber-js
demo say and what is the expected outcome.
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?
Post the exact output of the exact code and the expected output.
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.
Post a minimal code sample and highlight it appropriately.
var parsedGB = libphonenumberJs.parse(destination, 'GB'); var isValidGB = libphonenumberJs.isValidNumber(parsedGB.phone, 'GB');
where 'destination' is the number in question - 447797732133
Substitute the phone number to simplify the example. And highlight the code appropriately.
This should be adequate for you to try to reproduce it.
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.
Wow, I've never seen such a character on GitHub🤦
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.