catamphetamine / react-phone-number-input

React component for international phone number input
http://catamphetamine.gitlab.io/react-phone-number-input/
MIT License
924 stars 194 forks source link

phone number is not beign formated properly #395

Closed Talha8598 closed 2 years ago

Talha8598 commented 2 years ago

if i use normal phone number then it works fine but if i repeat the country code if accepts number greater then specified in limitMaxLength, as you can see below it is giving three different results for three different input formats

image

image

image

Code:

<PhoneInput placeholder="Enter phone number" value={"0900786012131312"} defaultCountry={"US"} limitMaxLength={true} onChange={(newVal)=>console.log(newVal)} />

catamphetamine commented 2 years ago

I've figured out why does it parse text "1 111 111 1111 1" as a national "significant" number "+1 111 111 1111".

As soon as the user has input "11", no format matches those "national number" digits in the "US" country metadata. Since no format matches, the number doesn't seem like a valid one, so it attempts to see if the user "forgot" to input a "+" at the start. And it looks like they might've to. So it acts as if the leading "+" is there, as if the user's input is "+11". See AsYouType.fixMissingPlus() function.

So, since national "significant" number "+1 111 111 1111", the limitMaxLength feature is working as expected.

catamphetamine commented 2 years ago

limitMaxLength operates on national "significant" number, not on the user's input.