Browse Source

Libphonenumber JS API is not able to parse numbers with missing '+' unlike Java.

pull/3770/head
mandlil 1 year ago
committed by GitHub
parent
commit
fba6a38d49
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions
  1. +1
    -1
      javascript/i18n/phonenumbers/phonenumberutil.js
  2. +18
    -0
      javascript/i18n/phonenumbers/phonenumberutil_test.js

+ 1
- 1
javascript/i18n/phonenumbers/phonenumberutil.js View File

@ -3852,7 +3852,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.maybeExtractCountryCode =
var generalDesc = defaultRegionMetadata.getGeneralDesc();
/** @type {!RegExp} */
var validNumberPattern =
new RegExp(generalDesc.getNationalNumberPatternOrDefault());
new RegExp('^(?:' + generalDesc.getNationalNumberPatternOrDefault() + ')$');
// Passing null since we don't need the carrier code.
this.maybeStripNationalPrefixAndCarrierCode(
potentialNationalNumber, defaultRegionMetadata, null);


+ 18
- 0
javascript/i18n/phonenumbers/phonenumberutil_test.js View File

@ -2758,6 +2758,24 @@ function testMaybeExtractCountryCode() {
} catch (e) {
fail('Should not have thrown an exception: ' + e.toString());
}
number = new i18n.phonenumbers.PhoneNumber();
try {
phoneNumber = '821064588888';
metadata = phoneUtil.getMetadataForRegion(RegionCode.KR);
countryCallingCode = 82;
numberToFill = new goog.string.StringBuffer();
assertEquals(
'Should have extracted the country calling code of the ' +
'region passed in',
countryCallingCode,
phoneUtil.maybeExtractCountryCode(
phoneNumber, metadata, numberToFill, true, number));
assertEquals(
'Did figure out CountryCodeSource correctly',
CCS.FROM_NUMBER_WITHOUT_PLUS_SIGN, number.getCountryCodeSource());
} catch (e) {
fail('Should not have thrown an exception: ' + e.toString());
}
}
function testParseNationalNumber() {


Loading…
Cancel
Save