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 218 forks source link

parsePhoneNumber([number],[code]) returns undefined for very long, invalid numbers #393

Closed PaparazzoKid closed 3 years ago

PaparazzoKid commented 3 years ago

For numbers containing more than 18 numerical characters, parsePhoneNumber() returns undefined using either max or min metadata.

A given number can be 18 numerical characters long with any additional spaces, brackets or hyphens and work fine, but one more numerical digit will fail.

This is obviously and easy fix for me, as I assume undefined means it's an invalid phone number? However, I'm guessing that any given value should return with an object but return false when checking isValid().

Tests

This returns with an object as expected (18 numerical long):

parsePhoneNumber('023203232332322322', 'GB)

This returns with an object as expected (18 numerical long with hyphens, brackets and spaces):

parsePhoneNumber('(023) 2032-32332322-322', 'GB)

This returns undefined (19 numerical long):

parsePhoneNumber('0232032323323223222', 'GB)

This returns undefined (19 numerical long with hyphens, brackets and spaces):

parsePhoneNumber('(023) 2032-32332322-3222', 'GB)

catamphetamine commented 3 years ago

For numbers containing more than 18 numerical characters, parsePhoneNumber() returns undefined using either max or min metadata.

Yes, because it's assumed a non-valid phone number, same as Google's library does.

However, I'm guessing that any given value should return with an object but return false when checking isValid().

No.

catamphetamine commented 3 years ago

https://github.com/google/libphonenumber/blob/master/FAQ.md#what-is-the-maximum-and-minimum-length-of-a-phone-number