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

parsePhoneNumberFromString returns undefined when only one digit entered after country code #382

Closed TaWReOn closed 4 years ago

TaWReOn commented 4 years ago

Steps to reproduce

I'm wondering why undefined value is returned in a code below:

const { parsePhoneNumberFromString } = phoneNumberJs.current; parsePhoneNumberFromString('+393'); // returns undefined parsePhoneNumberFromString('+3501') // returns undefined parsePhoneNumberFromString('+71') // returns undefined

What's the observed result?

undefined value is returned

What's the expected result?

expecting an object with a parsed phone number to be returned

catamphetamine commented 4 years ago

I'm wondering why undefined value is returned in a code below:

That's because having only one digit is not a valid phone number. The minimum is 3 digits. This is how it's implemented in google's code. See Google's demo.