Closed hbouhadji closed 4 years ago
Indeed, the library doesn't have this error correction feature. https://libphonenumber.appspot.com/phonenumberparser?number=33612902554+&country=FR I guess I won't be adding it currently though, but I'll leave this issue open just in case.
Same issue, seems I can call an external phone number w/o leading '+' from my iPhone so it's more or less a correct format
@DaveLomber There is a PR actually, i'm waiting @catamphetamine to review and merge it if it's correct for him
PR #324
@Hakim-Bou oh this is great ! will wait for @catamphetamine feedback
@Hakim-Bou Hello Hakim.
Yeah, I've seen your PR.
I'm currently having busy days and there're a couple of other penging bugs in libphonenumber-js
so I'm not merging it yet until I have enough free time to read my own code and compare it to how Google does it in their library (and also maybe merge some of their commits during this/past year).
But in future I guess this feature will be added because Google's library supports it.
Any news @catamphetamine ?
@Hakim-Bou It's funny but I still haven't looked into that because I was busy with other things. Perhaps in some future I'll look at it. But not now.
@Hakim-Bou I finally found some time to close issues in this library.
Your fix seems clever, but I don't feel like having such autocorrection feature in this library.
I guess Google has their reasons to correct any errors, but I personally feel like some errors should stay non-corrected, like omitting +
of an international number, or using a national prefix in AsYouType
when inputting an international number.
Still, there could be a way to implement such feature without forking the library and modifying its code directly. Something like this:
import { parsePhoneNumberFromString, getCountryCallingCode } from 'libphonenumber-js'
export default function autoFixParseNumber(number, country) {
const phoneNumber = parsePhoneNumberFromString(number, country)
if (phoneNumber) {
return phoneNumber
}
if (country && number[0] !== '+') {
if (number.indexOf(getCountryCallingCode(country)) === 0) {
number = number.slice(getCountryCallingCode(country).length)
return parsePhoneNumberFromString(number, country)
}
}
}
Such code could be called then from an application. This way, the feature won't be in the library, but would still be present in the application.
@Hakim-Bou Hello Hakim.
I reviewed your feature request recently, and agree that it's actually reasonable, so I've implemented the leading +
autocorrection feature in the new release libphonenumber-js@1.7.41
.
Thanks for the suggestion.
@catamphetamine Hello Nikolay, That's a great news, thanks you, I'm gonna give an eye on it
@catamphetamine that's seems good to me, except for the As you type method (https://catamphetamine.github.io/libphonenumber-js/)
@Hakim-Bou
that's seems good to me, except for the As you type method
Good point, forgot about the .getNumber()
method of AsYouType
.
Fixed in libphonenumber-js@1.7.42
.
To keep the code simpler, I didn't implement formatting of such numbers in AsYouType
— it'll be a form of taxation of users that input incorrect numbers: such numbers would still be parsed, but they won't be formatted.
@catamphetamine Perfect ! Thanks you 👍
Hello I have a question,
I want to accept some phonenumbers like:
33612902554
(FR country)If I try the google lib (https://rawgit.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/demo-compiled.html), the result is:
which is perfect for me, but with libphonenumber-js (https://catamphetamine.github.io/libphonenumber-js/) I have:
which is not good for me (+3333 ...), I know it's because I didn't add the '+' but it's working with the google lib.
Do you have an explanation to this please ? thanks you