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.79k stars 216 forks source link

Numbers without a leading plus are considered invalid. #179

Closed jpickwell closed 6 years ago

jpickwell commented 6 years ago

Passing a number like 18772155230 into isValidNumberCustom('18772155230', 'US', <US-only metadata>), the function returns false even though Google's library will indicate that it's valid.

https://rawgit.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/demo-compiled.html

catamphetamine commented 6 years ago

Did you pass --extended flag. It works with metadata.full.json. Your metadata is not complete.

image

catamphetamine commented 6 years ago

Oh, isValidNumber, maybe I'll test that one instead

catamphetamine commented 6 years ago

Still valid.

image

jpickwell commented 6 years ago

Let me try rebuilding my metadata.

jpickwell commented 6 years ago

Sorry about that. I completely forgot about updating the metadata after updating to a newer version of this library. I was already using the --extended flag, but was using outdated metadata. Thanks for the quick response.

catamphetamine commented 6 years ago

Ouch, you got me. The recent refactor added possibleLengths property and I didn't think about backwards-compatibility. It's true that some users generated metadata with the old version and don't re-generate metadata upon publishing the project. Maybe I should add some backwards compatibility.

catamphetamine commented 6 years ago

(added backwards compatibility)