Closed joallard closed 4 years ago
valid
means “valid for the country specified”.
On Fri, 24 Jan 2020 at 08:05, Jonathan Allard notifications@github.com wrote:
Entering a NANP country (US) as a default country, and entering a NANP number from another country, the library will return the number as invalid.
On the demo https://catamphetamine.github.io/libphonenumber-js/, section As you type:
- Enter 'US' as default country
- Enter '514 555-1212' as number
=> valid: false
I know the valid field is limited, but that seems kind of a stretch. Besides, "default country" doesn't mean "exactly this country".
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/catamphetamine/libphonenumber-js/issues/368?email_source=notifications&email_token=AADUP3374P6WWM2APJCCEPLQ7JZITA5CNFSM4KLBCL6KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IINWWTQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADUP33R6IM7KH4EOAGHODLQ7JZITANCNFSM4KLBCL6A .
If you want NANPA validation then pass international numbers instead, by prepending +1
in case of NANPA.
Thank you for your response. The UX issue has since stopped existing, as users realized they were wrong. I will add a tooltip "Dear human, please take a few seconds of your existence to change the country in the dropdown menu or add "+1" even though the format is the same, just to satisfy this computer library code"
I see, so you've fixed it. Just to reiterate: validation and phone number input are completely different tasks and shouldn't be mixed and should be performed at different stages.
For example, inputting a phone number is AsYouType('US')
, and validating it for any country afterwards is parsePhoneNumberFromString(asYouType.getNumber().number).isValid()
.
Entering a NANP country (US) as a default country, and entering a NANP number from another country, the library will return the number as invalid.
On the demo, section As you type:
=>
valid: false
I know the
valid
field is limited, but that seems kind of a stretch. Besides, "default country" doesn't mean "exactly this country".