catamphetamine / react-phone-number-input

React component for international phone number input

Home Page:http://catamphetamine.gitlab.io/react-phone-number-input/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

phone number is not beign formated properly

Talha8598 opened this issue · comments

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)}
/>

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.

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