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

isValid() and e164 format #421

Closed sbungert-mms closed 1 year ago

sbungert-mms commented 2 years ago

Is there any function like isValid that will validate a phone number as being compliant for E164?

E164 numbers need to have at most 15 numbers and no special chars except a leading +, how can I validate that there are not too many digits? Is there some API method of doing this? Or should manually check if there are not to many digits?

validatePhoneNumberLength seems to require a country code and makes sure the phonenumber is within the bounds of a country specific number, but for E164 I don't need to know about the country. I just want to check that there are not more than 15 digits

catamphetamine commented 2 years ago

E164 numbers need to have at most 15 numbers and no special chars except a leading +

Can you provide a reference to a reputable source?

how can I validate that there are not too many digits? Is there some API method of doing this?

Currently there's no restriction on such phone numbers' length.

but for E164 I don't need to know about the country.

That's true.

hanselsen commented 1 year ago

@catamphetamine I have the same request. Please check my sandbox here https://codesandbox.io/s/libphonenumber-js-e-164-iyhlrx For reference on E.164, check https://www.itu.int/rec/T-REC-E.164-201011-I/en

I hope this can be fixed.

catamphetamine commented 1 year ago

@hanselsen

I have the same request.

What request?

hanselsen commented 1 year ago

@catamphetamine to have the isValidPhoneNumber take the 15 digit number into consideration. That would be great.