Closed timt closed 6 years ago
This is most likely because:
https://github.com/catamphetamine/libphonenumber-js#bug-reporting
Phone number validation bugs should only be reported if they appear when using custom metadata functions fed with metadata.full.json because by default all functions in this library use the reduced metadata set which results in looser validation than the original Google libphonenumber's. The demo page also uses the reduced metadata set and therefore its validation is also looser than the original Google libphonenumber's.
Closing until proven otherwise.
Oh, actually, that's not the case, because it's not looser in this case, it's stricter.
So I fixed isValidNumber
in version 1.3.0
and also added a stricter one (isValidNumberForRegion()
).
https://github.com/catamphetamine/libphonenumber-js#isvalidnumbernumber-defaultcountry
The optional defaultCountry
argument is the default country, i.e. it does not restrict to just that country, e.g. in those cases where several countries share the same phone numbering rules (NANPA, Britain, etc). For example, even though the number 07624 369230
belongs to the Isle of Man ("IM" country code) calling isValidNumber('07624369230', 'GB')
still returns true
because the country is not restricted to GB
, it's just that GB
is the default one for the phone numbering rules. For restricting the country see isValidNumberForRegion()
though restricting a country might not be a good idea.
// Even though '07624 369230' number belongs to the Isle of Man ("IM")
// the `defaultCountry` argument "GB" still works here because
// "GB" and "IM" both share the same phone numbering rules ("+44").
isValidNumber('07624369230', 'GB') === true
isValidNumber('07624369230', 'IM') === true
// Imposing country restrictions.
isValidNumberForRegion('07624369230', 'GB') === false
isValidNumberForRegion('07624369230', 'IM') === true
Thank you for the quick turn around.
Observe behaviour in libphonenumber-js demo: Entered phone number 07624369230 and country GB Demo shows number as Valid: false (see screen shot)
Observed behaviour on Googles libphonenumber demo page shows that this number and country is Valid https://libphonenumber.appspot.com/phonenumberparser?number=07624369230&country=GB