catamphetamine / libphonenumber-js

A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript
https://catamphetamine.gitlab.io/libphonenumber-js/
MIT License
2.77k stars 217 forks source link

Vietnam Phone Number Validation Failed #284

Closed shanafme closed 5 years ago

shanafme commented 5 years ago

This number: +841664223299 (Vietnam)

Is failing Google's libphonenumber IsValid Check at https://libphonenumber.appspot.com/phonenumberparser?number=%2B841664223299.

But is passing the Valid check at libphonenumber-js: image

catamphetamine commented 5 years ago

I updated the readme with a more detailed explanation of such case:

isValid()

Checks if the phone number is "valid". First checks the phone number length and then checks the phone number digits against all available regular expressions.

By default the library uses "minimal" metadata which is only 75 kilobytes in size but also doesn't include most of the validation regular expressions resulting in less strict validation rules (some very basic validation is still included for each country). If you don't mind the extra 65 kilobytes of metadata then use "full" metadata instead (140 kilobytes) (see Customizing metadata section of this document) for validating phone numbers. Google's library always uses "full" metadata so it will yield different isValidNumber() results compared to the "minimal" metadata used by default in this library.

See also "Using phone number validation feature" considerations.

getType()

Returns phone number type (fixed line, mobile, toll free, etc) or undefined (if the number is invalid or if there are no phone number type regular expressions for this country in metadata).

By default the library uses "minimal" metadata which is only 75 kilobytes in size but also doesn't include most of the regular expressions corresponding to each specific phone number type (fixed line, mobile, toll free, etc) resulting in getType() returning undefined in most cases. If you don't mind the extra 65 kilobytes of metadata then use "full" metadata instead (140 kilobytes) (see Customizing metadata section of this document) for getting phone number type. Google's library always uses "full" metadata so it will yield different getNumberType() results compared to the "minimal" metadata used by default in this library.