Comments (1)
Hmm, yeah, this behaviour seems like a bug which isn't really a bug.
Google's libphonenumber
was originally created to match phone numbers in a non-strict matter meaning that it would rather attempt to parse a strictly speaking invalid phone number than just dismiss it (it's like web browsers render HTML – they prefer to render at least something as long as they can do that).
So, Google's library behaviour is the same:
https://libphonenumber.appspot.com/phonenumberparser?number=%2B330612345678&country=US
Analogous, it doesn't format the phone number in as you type formatter and it also considers this kind of a phone number valid.
I could introduce some kind of a { strict: true }
option which would be passed to parse(number, options)
and parse()
could return nothing if the number
is international and contains a national prefix.
Still, from a website owner's perspective it's better to not loose clients just because they don't know how to write their phone numbers right.
If your website is for France only then you should use local phone number format.
It will suit grandma.
But the younger generation may not know how to input a local phone number, they will want to do that in international format.
Therefore, I think, the best way is to accept both local and international phone numbers: if the first sign in +
then switch to international parsing mode; if not – switch to local parsing mode.
This is the behaviour of react-phone-number-input
http://halt-hammerzeit.github.io/react-phone-number-input/
So, in summary, this behaviour is exactly what Google's library does, and I could introduce a special { strict: true }
flag for parsing but almost anyone would prefer to forgive such input errors not to loose customers.
If you highlight such a phone number as "wrong" the customer may not know what's wrong and may just navigate away from the website (not placing the order).
The formatting is not critical in this case because it doesn't limit functionality.
I guess this sums it up.
from libphonenumber-js.
Related Issues (20)
- parsePhoneNumberWithError() return isValid() === 'false' but not throw an error HOT 3
- Some HK mobile numbers (9291****) are not yet supported in this library HOT 1
- Belgium phone number are valid even if they can't be parsed for national display HOT 1
- When using AsYouType with US Country code, if number starts with 1 it formats incorrectly. HOT 1
- country code duplication for some countries HOT 2
- ParsePhoneNumber mistakes the two first digits as the country code HOT 1
- When editing a formatted number the cursor moves to the end HOT 1
- Get countryCode, countryName, countryFlag object HOT 4
- isValidPhoneNumber function return wrong result HOT 1
- +15575001171 number not validated as valid phone number when it is valid by Google's libphonenumber HOT 5
- isValidPhoneNumber and parsePhoneNumber validate the number incorrectly HOT 6
- Missing area code 861 HOT 1
- ts(1479) error in index.d.cts HOT 3
- Unable to delete characters if there is a parenthesis HOT 1
- Any property returns area code? HOT 3
- Different Results | Real Life vs Demo HOT 2
- validatePhoneNumberLength does not return TOO_LONG for invalid Ukrainian phone number HOT 9
- Some North American countries receive incorrect National Format when removing digits
- Cuba added a new prefix 63 to phone number HOT 1
- New HK Hutchison telecom mobile number range not yet updated HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libphonenumber-js.