I have a react app with an input field for users to write their phone number which is saved as a state, then parsed, then displayed back into the input field. This means that the string is parsed each time a new digit is typed into the input field.
Most of the telephone numbers are Norwegian, which has a country code of 47. The issue is occurs when the phone number (with no prefix) starts with 470.
After typing in the 7th digit, the parsePhoneNumber method suddenly thinks the 47 is the country code rather than the number itself.
Example
Imagine that as the user types in their phone number this is whats being parsed:
I have a react app with an input field for users to write their phone number which is saved as a state, then parsed, then displayed back into the input field. This means that the string is parsed each time a new digit is typed into the input field.
Most of the telephone numbers are Norwegian, which has a country code of 47. The issue is occurs when the phone number (with no prefix) starts with 470.
After typing in the 7th digit, the parsePhoneNumber method suddenly thinks the 47 is the country code rather than the number itself.
Example
Imagine that as the user types in their phone number this is whats being parsed:
The output is:
Notice the nationalNumber on the second row.
This is especially a problem when using the state in the input field as the two first digits og the number will dissapear as the user is typing.
So is this a bug, or is there a way to work around it?