void OnEntryTextChanged(object sender, TextChangedEventArgs args) { if (args.NewTextValue.Length == 0) { formatter.Clear(); ((Entry)sender).Text = args.NewTextValue; } else { formatter.Clear(); string formattedNumber = ""; foreach (char digit in args.NewTextValue.Replace(" ", "").Replace("(", "").Replace(")", "").Replace("-", "").Replace("+", "")) { formattedNumber = formatter.InputDigit(digit); } PhoneNumber phoneNumber = new PhoneNumber.Builder() .SetCountryCode(1) .SetNationalNumber(ulong.Parse(formattedNumber.Replace(" ", "").Replace("(", "").Replace(")", "").Replace("-", "").Replace("+", ""))) .Build(); bool isValid = PhoneNumberUtil.GetInstance().IsValidNumber(phoneNumber); ((Entry)sender).TextColor = isValid ? Color.Green : Color.DarkRed; ((Entry)sender).Text = formattedNumber; } }
public void TestLookupInvalidNumber_US() { // central office code cannot start with 1. var number = new PhoneNumber.Builder().SetCountryCode(1).SetNationalNumber(2121234567L).Build(); Assert.AreEqual("New York", areaCodeMapForUS.Lookup(number)); }
public void TestLookupNumber_IT() { var number = new PhoneNumber.Builder().SetCountryCode(39).SetNationalNumber(212345678L).SetItalianLeadingZero(true) .Build(); Assert.AreEqual("Milan", areaCodeMapForIT.Lookup(number)); number = new PhoneNumber.Builder().SetCountryCode(39).SetNationalNumber(612345678L).SetItalianLeadingZero(true) .Build(); Assert.AreEqual("Rome", areaCodeMapForIT.Lookup(number)); number = new PhoneNumber.Builder().SetCountryCode(39).SetNationalNumber(3211234L).SetItalianLeadingZero(true) .Build(); Assert.AreEqual("Novara", areaCodeMapForIT.Lookup(number)); // A mobile number number = new PhoneNumber.Builder().SetCountryCode(39).SetNationalNumber(321123456L).SetItalianLeadingZero(false) .Build(); Assert.IsNull(areaCodeMapForIT.Lookup(number)); // An invalid number (too short) number = new PhoneNumber.Builder().SetCountryCode(39).SetNationalNumber(321123L).SetItalianLeadingZero(true) .Build(); Assert.AreEqual("Novara", areaCodeMapForIT.Lookup(number)); }
public void TestMatchesMultiplePhoneNumbersSeparatedByPhoneNumberPunctuation() { const string text = "Call 650-253-4561 -- 455-234-3451"; const string region = "US"; var number1 = new PhoneNumber.Builder() .SetCountryCode(phoneUtil.GetCountryCodeForRegion(region)) .SetNationalNumber(6502534561L) .Build(); var match1 = new PhoneNumberMatch(5, "650-253-4561", number1); var number2 = new PhoneNumber.Builder() .SetCountryCode(phoneUtil.GetCountryCodeForRegion(region)) .SetNationalNumber(4552343451L) .Build(); var match2 = new PhoneNumberMatch(21, "455-234-3451", number2); var matches = phoneUtil.FindNumbers(text, region).GetEnumerator(); matches.MoveNext(); Assert.Equal(match1, matches.Current); matches.MoveNext(); Assert.Equal(match2, matches.Current); matches.Dispose(); }
public void TestIsSmsService() { var smsServiceNumberForSomeRegion = new PhoneNumber.Builder().SetCountryCode(1).SetNationalNumber(21234L).Build(); Assert.True(ShortInfo.IsSmsServiceForRegion(smsServiceNumberForSomeRegion, RegionCode.US)); Assert.False(ShortInfo.IsSmsServiceForRegion(smsServiceNumberForSomeRegion, RegionCode.BB)); }
public void TestEqualWithPreferredDomesticCarrierCodeSetToDefault() { var numberA = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).SetPreferredDomesticCarrierCode("").Build(); var numberB = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).SetPreferredDomesticCarrierCode("").Build(); Assert.Equal(numberA, numberB); Assert.Equal(numberA.GetHashCode(), numberB.GetHashCode()); }
public void TestNonEqualWithItalianLeadingZeroSetToTrue() { var numberA = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).SetItalianLeadingZero(true).Build(); var numberB = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).Build(); Assert.False(numberA.Equals(numberB)); Assert.False(numberA.GetHashCode() == numberB.GetHashCode()); }
public void TestNonEqualWithPreferredDomesticCarrierCodeSetToDefault() { PhoneNumber numberA = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).SetPreferredDomesticCarrierCode("").Build(); PhoneNumber numberB = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).Build(); Assert.IsFalse(numberA.Equals(numberB)); Assert.IsFalse(numberA.GetHashCode() == numberB.GetHashCode()); }
public void TestEqualWithCountryCodeSourceSet() { PhoneNumber numberA = new PhoneNumber.Builder() .SetRawInput("+1 650 253 00 00"). SetCountryCodeSource(PhoneNumber.Types.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN).BuildPartial(); PhoneNumber numberB = new PhoneNumber.Builder() .SetRawInput("+1 650 253 00 00"). SetCountryCodeSource(PhoneNumber.Types.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN).BuildPartial(); Assert.AreEqual(numberA, numberB); Assert.AreEqual(numberA.GetHashCode(), numberB.GetHashCode()); }
public void TestEqualSimpleNumber() { var numberA = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).Build(); var numberB = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).Build(); Assert.Equal(numberA, numberB); Assert.Equal(numberA.GetHashCode(), numberB.GetHashCode()); }
public void TestNonEqualWithItalianLeadingZeroSetToTrue() { PhoneNumber numberA = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).SetItalianLeadingZero(true).Build(); PhoneNumber numberB = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).Build(); Assert.IsFalse(numberA.Equals(numberB)); Assert.IsFalse(numberA.GetHashCode() == numberB.GetHashCode()); }
public void TestEqualSimpleNumber() { PhoneNumber numberA = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).Build(); PhoneNumber numberB = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).Build(); Assert.AreEqual(numberA, numberB); Assert.AreEqual(numberA.GetHashCode(), numberB.GetHashCode()); }
public void TestEqualWithItalianLeadingZeroSetToDefault() { PhoneNumber numberA = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).SetItalianLeadingZero(false).Build(); PhoneNumber numberB = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).Build(); // These should still be equal, since the default value for this field is false. Assert.AreEqual(numberA, numberB); Assert.AreEqual(numberA.GetHashCode(), numberB.GetHashCode()); }
public void TestGetExpectedCostForSharedCountryCallingCode() { // Test some numbers which have different costs in countries sharing the same country calling // code. In Australia, 1234 is premium-rate, 1194 is standard-rate, and 733 is toll-free. These // are not known to be valid numbers in the Christmas Islands. var ambiguousPremiumRateString = "1234"; var ambiguousPremiumRateNumber = new PhoneNumber.Builder().SetCountryCode(61).SetNationalNumber(1234L).Build(); var ambiguousStandardRateString = "1194"; var ambiguousStandardRateNumber = new PhoneNumber.Builder().SetCountryCode(61).SetNationalNumber(1194L).Build(); var ambiguousTollFreeString = "733"; var ambiguousTollFreeNumber = new PhoneNumber.Builder().SetCountryCode(61).SetNationalNumber(733L).Build(); Assert.True(ShortInfo.IsValidShortNumber(ambiguousPremiumRateNumber)); Assert.True(ShortInfo.IsValidShortNumber(ambiguousStandardRateNumber)); Assert.True(ShortInfo.IsValidShortNumber(ambiguousTollFreeNumber)); Assert.True(ShortInfo.IsValidShortNumberForRegion( Parse(ambiguousPremiumRateString, RegionCode.AU), RegionCode.AU)); Assert.Equal(ShortNumberInfo.ShortNumberCost.PREMIUM_RATE, ShortInfo.GetExpectedCostForRegion( Parse(ambiguousPremiumRateString, RegionCode.AU), RegionCode.AU)); Assert.False(ShortInfo.IsValidShortNumberForRegion( Parse(ambiguousPremiumRateString, RegionCode.CX), RegionCode.CX)); Assert.Equal(ShortNumberInfo.ShortNumberCost.UNKNOWN_COST, ShortInfo.GetExpectedCostForRegion( Parse(ambiguousPremiumRateString, RegionCode.CX), RegionCode.CX)); // PREMIUM_RATE takes precedence over UNKNOWN_COST. Assert.Equal(ShortNumberInfo.ShortNumberCost.PREMIUM_RATE, ShortInfo.GetExpectedCost(ambiguousPremiumRateNumber)); Assert.True(ShortInfo.IsValidShortNumberForRegion( Parse(ambiguousStandardRateString, RegionCode.AU), RegionCode.AU)); Assert.Equal(ShortNumberInfo.ShortNumberCost.STANDARD_RATE, ShortInfo.GetExpectedCostForRegion( Parse(ambiguousStandardRateString, RegionCode.AU), RegionCode.AU)); Assert.False(ShortInfo.IsValidShortNumberForRegion( Parse(ambiguousStandardRateString, RegionCode.CX), RegionCode.CX)); Assert.Equal(ShortNumberInfo.ShortNumberCost.UNKNOWN_COST, ShortInfo.GetExpectedCostForRegion( Parse(ambiguousStandardRateString, RegionCode.CX), RegionCode.CX)); Assert.Equal(ShortNumberInfo.ShortNumberCost.UNKNOWN_COST, ShortInfo.GetExpectedCost(ambiguousStandardRateNumber)); Assert.True(ShortInfo.IsValidShortNumberForRegion(Parse(ambiguousTollFreeString, RegionCode.AU), RegionCode.AU)); Assert.Equal(ShortNumberInfo.ShortNumberCost.TOLL_FREE, ShortInfo.GetExpectedCostForRegion( Parse(ambiguousTollFreeString, RegionCode.AU), RegionCode.AU)); Assert.False(ShortInfo.IsValidShortNumberForRegion(Parse(ambiguousTollFreeString, RegionCode.CX), RegionCode.CX)); Assert.Equal(ShortNumberInfo.ShortNumberCost.UNKNOWN_COST, ShortInfo.GetExpectedCostForRegion( Parse(ambiguousTollFreeString, RegionCode.CX), RegionCode.CX)); Assert.Equal(ShortNumberInfo.ShortNumberCost.UNKNOWN_COST, ShortInfo.GetExpectedCost(ambiguousTollFreeNumber)); }
public void TestEqualWithCountryCodeSourceSet() { var numberA = new PhoneNumber.Builder() .SetRawInput("+1 650 253 00 00"). SetCountryCodeSource(PhoneNumber.Types.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN).BuildPartial(); var numberB = new PhoneNumber.Builder() .SetRawInput("+1 650 253 00 00"). SetCountryCodeSource(PhoneNumber.Types.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN).BuildPartial(); Assert.Equal(numberA, numberB); Assert.Equal(numberA.GetHashCode(), numberB.GetHashCode()); }
public void TestNonEqualWithDifferingRawInput() { PhoneNumber numberA = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).SetRawInput("+1 650 253 00 00") .SetCountryCodeSource(PhoneNumber.Types.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN).Build(); PhoneNumber numberB = new PhoneNumber.Builder() // Although these numbers would pass an isNumberMatch test, they are not considered "equal" as // objects, since their raw input is different. .SetCountryCode(1).SetNationalNumber(6502530000L).SetRawInput("+1-650-253-00-00"). SetCountryCodeSource(PhoneNumber.Types.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN).Build(); Assert.IsFalse(numberA.Equals(numberB)); Assert.IsFalse(numberA.GetHashCode() == numberB.GetHashCode()); }
public void TestNonEqualWithDifferingRawInput() { var numberA = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(6502530000L).SetRawInput("+1 650 253 00 00") .SetCountryCodeSource(PhoneNumber.Types.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN).Build(); var numberB = new PhoneNumber.Builder() // Although these numbers would pass an isNumberMatch test, they are not considered "equal" as // objects, since their raw input is different. .SetCountryCode(1).SetNationalNumber(6502530000L).SetRawInput("+1-650-253-00-00"). SetCountryCodeSource(PhoneNumber.Types.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN).Build(); Assert.False(numberA.Equals(numberB)); Assert.False(numberA.GetHashCode() == numberB.GetHashCode()); }
public void TestIsPossibleShortNumber() { var possibleNumber = new PhoneNumber.Builder().SetCountryCode(33).SetNationalNumber(123456L).Build(); Assert.True(ShortInfo.IsPossibleShortNumber(possibleNumber)); Assert.True( ShortInfo.IsPossibleShortNumberForRegion(Parse("123456", RegionCode.FR), RegionCode.FR)); var impossibleNumber = new PhoneNumber.Builder().SetCountryCode(33).SetNationalNumber(9L).Build(); Assert.False(ShortInfo.IsPossibleShortNumber(impossibleNumber)); // Note that GB and GG share the country calling code 44, and that this number is possible but // not valid. Assert.True(ShortInfo.IsPossibleShortNumber( new PhoneNumber.Builder().SetCountryCode(44).SetNationalNumber(11001L).Build())); }
public void TestEmergencyNumberForSharedCountryCallingCode() { // Test the emergency number 112, which is valid in both Australia and the Christmas Islands. Assert.True(ShortInfo.IsEmergencyNumber("112", RegionCode.AU)); Assert.True(ShortInfo.IsValidShortNumberForRegion(Parse("112", RegionCode.AU), RegionCode.AU)); Assert.Equal(ShortNumberInfo.ShortNumberCost.TOLL_FREE, ShortInfo.GetExpectedCostForRegion(Parse("112", RegionCode.AU), RegionCode.AU)); Assert.True(ShortInfo.IsEmergencyNumber("112", RegionCode.CX)); Assert.True(ShortInfo.IsValidShortNumberForRegion(Parse("112", RegionCode.CX), RegionCode.CX)); Assert.Equal(ShortNumberInfo.ShortNumberCost.TOLL_FREE, ShortInfo.GetExpectedCostForRegion(Parse("112", RegionCode.CX), RegionCode.CX)); var sharedEmergencyNumber = new PhoneNumber.Builder().SetCountryCode(61).SetNationalNumber(112L).Build(); Assert.True(ShortInfo.IsValidShortNumber(sharedEmergencyNumber)); Assert.Equal(ShortNumberInfo.ShortNumberCost.TOLL_FREE, ShortInfo.GetExpectedCost(sharedEmergencyNumber)); }
public void TestSequences() { // Test multiple occurrences. String text = "Call 033316005 or 032316005!"; String region = "NZ"; PhoneNumber number1 = new PhoneNumber.Builder() .SetCountryCode(phoneUtil.GetCountryCodeForRegion(region)) .SetNationalNumber(33316005).Build(); PhoneNumberMatch match1 = new PhoneNumberMatch(5, "033316005", number1); PhoneNumber number2 = new PhoneNumber.Builder() .SetCountryCode(phoneUtil.GetCountryCodeForRegion(region)) .SetNationalNumber(32316005).Build(); PhoneNumberMatch match2 = new PhoneNumberMatch(19, "032316005", number2); var matches = phoneUtil.FindNumbers(text, region, PhoneNumberUtil.Leniency.POSSIBLE, long.MaxValue).GetEnumerator(); matches.MoveNext(); Assert.Equal(match1, matches.Current); matches.MoveNext(); Assert.Equal(match2, matches.Current); }
public void TestIsCarrierSpecific() { var carrierSpecificNumber = new PhoneNumber.Builder().SetCountryCode(1).SetNationalNumber(33669L).Build(); Assert.True(ShortInfo.IsCarrierSpecific(carrierSpecificNumber)); Assert.True( ShortInfo.IsCarrierSpecificForRegion(Parse("33669", RegionCode.US), RegionCode.US)); var notCarrierSpecificNumber = new PhoneNumber.Builder().SetCountryCode(1).SetNationalNumber(911L).Build(); Assert.False(ShortInfo.IsCarrierSpecific(notCarrierSpecificNumber)); Assert.False( ShortInfo.IsCarrierSpecificForRegion(Parse("911", RegionCode.US), RegionCode.US)); var carrierSpecificNumberForSomeRegion = new PhoneNumber.Builder().SetCountryCode(1).SetNationalNumber(211L).Build(); Assert.True(ShortInfo.IsCarrierSpecific(carrierSpecificNumberForSomeRegion)); Assert.True( ShortInfo.IsCarrierSpecificForRegion(carrierSpecificNumberForSomeRegion, RegionCode.US)); Assert.False( ShortInfo.IsCarrierSpecificForRegion(carrierSpecificNumberForSomeRegion, RegionCode.BB)); }
public void TestLookupNumber_CA_2() { var number = new PhoneNumber.Builder().SetCountryCode(1).SetNationalNumber(6502531234L).Build(); Assert.AreEqual("California", areaCodeMapForUS.Lookup(number)); }
public void TestLookupNumber_NY() { var number = new PhoneNumber.Builder().SetCountryCode(1).SetNationalNumber(2126641234L).Build(); Assert.AreEqual("New York", areaCodeMapForUS.Lookup(number)); }
public void TestIsNumberMatchShortNsnMatches() { // Short NSN matches with the country not specified for either one or both numbers. Assert.AreEqual(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.IsNumberMatch("+64 3 331-6005", "331 6005")); Assert.AreEqual(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.IsNumberMatch("+64 3 331-6005", "tel:331-6005;phone-context=abc.nz")); Assert.AreEqual(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.IsNumberMatch("+64 3 331-6005", "tel:331-6005;isub=1234;phone-context=abc.nz")); Assert.AreEqual(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.IsNumberMatch("+64 3 331-6005", "tel:331-6005;isub=1234;phone-context=abc.nz;a=%A1")); // We did not know that the "0" was a national prefix since neither number has a country code, // so this is considered a SHORT_NSN_MATCH. Assert.AreEqual(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.IsNumberMatch("3 331-6005", "03 331 6005")); Assert.AreEqual(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.IsNumberMatch("3 331-6005", "331 6005")); Assert.AreEqual(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.IsNumberMatch("3 331-6005", "tel:331-6005;phone-context=abc.nz")); Assert.AreEqual(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.IsNumberMatch("3 331-6005", "+64 331 6005")); // Short NSN match with the country specified. Assert.AreEqual(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.IsNumberMatch("03 331-6005", "331 6005")); Assert.AreEqual(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.IsNumberMatch("1 234 345 6789", "345 6789")); Assert.AreEqual(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.IsNumberMatch("+1 (234) 345 6789", "345 6789")); // NSN matches, country calling code omitted for one number, extension missing for one. Assert.AreEqual(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.IsNumberMatch("+64 3 331-6005", "3 331 6005#1234")); // One has Italian leading zero, one does not. PhoneNumber italianNumberOne = new PhoneNumber.Builder() .SetCountryCode(39).SetNationalNumber(1234L).SetItalianLeadingZero(true).Build(); PhoneNumber italianNumberTwo = new PhoneNumber.Builder() .SetCountryCode(39).SetNationalNumber(1234L).Build(); Assert.AreEqual(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.IsNumberMatch(italianNumberOne, italianNumberTwo)); // One has an extension, the other has an extension of "". italianNumberOne = Update(italianNumberOne).SetExtension("1234").ClearItalianLeadingZero().Build(); italianNumberTwo = Update(italianNumberTwo).SetExtension("").Build(); Assert.AreEqual(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.IsNumberMatch(italianNumberOne, italianNumberTwo)); }
public void TestLookupNumber_CH() { var number = new PhoneNumber.Builder().SetCountryCode(41).SetNationalNumber(446681300L).Build(); Assert.IsNull(areaCodeMapForUS.Lookup(number)); }
public void TestLookupNumberFound_TX() { var number = new PhoneNumber.Builder().SetCountryCode(1).SetNationalNumber(9724801234L).Build(); Assert.AreEqual("Richardson, TX", areaCodeMapForUS.Lookup(number)); }
public void TestMatchesMultiplePhoneNumbersSeparatedByPhoneNumberPunctuation() { String text = "Call 650-253-4561 -- 455-234-3451"; String region = "US"; PhoneNumber number1 = new PhoneNumber.Builder() .SetCountryCode(phoneUtil.GetCountryCodeForRegion(region)) .SetNationalNumber(6502534561L) .Build(); PhoneNumberMatch match1 = new PhoneNumberMatch(5, "650-253-4561", number1); PhoneNumber number2 = new PhoneNumber.Builder() .SetCountryCode(phoneUtil.GetCountryCodeForRegion(region)) .SetNationalNumber(4552343451L) .Build(); PhoneNumberMatch match2 = new PhoneNumberMatch(21, "455-234-3451", number2); var matches = phoneUtil.FindNumbers(text, region).GetEnumerator(); matches.MoveNext(); Assert.AreEqual(match1, matches.Current); matches.MoveNext(); Assert.AreEqual(match2, matches.Current); }
public void TestIsNumberMatchNsnMatches() { // NSN matches. Assert.AreEqual(PhoneNumberUtil.MatchType.NSN_MATCH, phoneUtil.IsNumberMatch("+64 3 331-6005", "03 331 6005")); Assert.AreEqual(PhoneNumberUtil.MatchType.NSN_MATCH, phoneUtil.IsNumberMatch( "+64 3 331-6005", "tel:03-331-6005;isub=1234;phone-context=abc.nz")); Assert.AreEqual(PhoneNumberUtil.MatchType.NSN_MATCH, phoneUtil.IsNumberMatch(NZ_NUMBER, "03 331 6005")); // Here the second number possibly starts with the country calling code for New Zealand, // although we are unsure. PhoneNumber unchangedNzNumber = new PhoneNumber.Builder().MergeFrom(NZ_NUMBER).Build(); Assert.AreEqual(PhoneNumberUtil.MatchType.NSN_MATCH, phoneUtil.IsNumberMatch(unchangedNzNumber, "(64-3) 331 6005")); // Check the phone number proto was not edited during the method call. Assert.AreEqual(NZ_NUMBER, unchangedNzNumber); // Here, the 1 might be a national prefix, if we compare it to the US number, so the resultant // match is an NSN match. Assert.AreEqual(PhoneNumberUtil.MatchType.NSN_MATCH, phoneUtil.IsNumberMatch(US_NUMBER, "1-650-253-0000")); Assert.AreEqual(PhoneNumberUtil.MatchType.NSN_MATCH, phoneUtil.IsNumberMatch(US_NUMBER, "6502530000")); Assert.AreEqual(PhoneNumberUtil.MatchType.NSN_MATCH, phoneUtil.IsNumberMatch("+1 650-253 0000", "1 650 253 0000")); Assert.AreEqual(PhoneNumberUtil.MatchType.NSN_MATCH, phoneUtil.IsNumberMatch("1 650-253 0000", "1 650 253 0000")); Assert.AreEqual(PhoneNumberUtil.MatchType.NSN_MATCH, phoneUtil.IsNumberMatch("1 650-253 0000", "+1 650 253 0000")); // For this case, the match will be a short NSN match, because we cannot assume that the 1 might // be a national prefix, so don't remove it when parsing. PhoneNumber randomNumber = new PhoneNumber.Builder() .SetCountryCode(41).SetNationalNumber(6502530000L).Build(); Assert.AreEqual(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.IsNumberMatch(randomNumber, "1-650-253-0000")); }
public void TestFormatNumberWithExtension() { PhoneNumber nzNumber = new PhoneNumber.Builder().MergeFrom(NZ_NUMBER).SetExtension("1234").Build(); // Uses default extension prefix: Assert.AreEqual("03-331 6005 ext. 1234", phoneUtil.Format(nzNumber, PhoneNumberFormat.NATIONAL)); // Uses RFC 3966 syntax. Assert.AreEqual("tel:+64-3-331-6005;ext=1234", phoneUtil.Format(nzNumber, PhoneNumberFormat.RFC3966)); // Extension prefix overridden in the territory information for the US: PhoneNumber usNumberWithExtension = new PhoneNumber.Builder().MergeFrom(US_NUMBER) .SetExtension("4567").Build(); Assert.AreEqual("650 253 0000 extn. 4567", phoneUtil.Format(usNumberWithExtension, PhoneNumberFormat.NATIONAL)); }
public void TestIsPremiumRate() { Assert.AreEqual(PhoneNumberType.PREMIUM_RATE, phoneUtil.GetNumberType(US_PREMIUM)); PhoneNumber premiumRateNumber = new PhoneNumber.Builder() .SetCountryCode(39).SetNationalNumber(892123L).Build(); Assert.AreEqual(PhoneNumberType.PREMIUM_RATE, phoneUtil.GetNumberType(premiumRateNumber)); premiumRateNumber = Update(premiumRateNumber).SetCountryCode(44).SetNationalNumber(9187654321L).Build(); Assert.AreEqual(PhoneNumberType.PREMIUM_RATE, phoneUtil.GetNumberType(premiumRateNumber)); premiumRateNumber = Update(premiumRateNumber).SetCountryCode(49).SetNationalNumber(9001654321L).Build(); Assert.AreEqual(PhoneNumberType.PREMIUM_RATE, phoneUtil.GetNumberType(premiumRateNumber)); premiumRateNumber = Update(premiumRateNumber).SetCountryCode(49).SetNationalNumber(90091234567L).Build(); Assert.AreEqual(PhoneNumberType.PREMIUM_RATE, phoneUtil.GetNumberType(premiumRateNumber)); Assert.AreEqual(PhoneNumberType.PREMIUM_RATE, phoneUtil.GetNumberType(UNIVERSAL_PREMIUM_RATE)); }
public void TestGetExpectedCost() { var premiumRateExample = ShortInfo.GetExampleShortNumberForCost(RegionCode.FR, ShortNumberInfo.ShortNumberCost.PREMIUM_RATE); Assert.Equal(ShortNumberInfo.ShortNumberCost.PREMIUM_RATE, ShortInfo.GetExpectedCostForRegion( Parse(premiumRateExample, RegionCode.FR), RegionCode.FR)); var premiumRateNumber = new PhoneNumber.Builder().SetCountryCode(33) .SetNationalNumber(ulong.Parse(premiumRateExample)).Build(); Assert.Equal(ShortNumberInfo.ShortNumberCost.PREMIUM_RATE, ShortInfo.GetExpectedCost(premiumRateNumber)); var standardRateExample = ShortInfo.GetExampleShortNumberForCost(RegionCode.FR, ShortNumberInfo.ShortNumberCost.STANDARD_RATE); Assert.Equal(ShortNumberInfo.ShortNumberCost.STANDARD_RATE, ShortInfo.GetExpectedCostForRegion( Parse(standardRateExample, RegionCode.FR), RegionCode.FR)); var standardRateNumber = new PhoneNumber.Builder().SetCountryCode(33) .SetNationalNumber(ulong.Parse(standardRateExample)).Build(); Assert.Equal(ShortNumberInfo.ShortNumberCost.STANDARD_RATE, ShortInfo.GetExpectedCost(standardRateNumber)); var tollFreeExample = ShortInfo.GetExampleShortNumberForCost(RegionCode.FR, ShortNumberInfo.ShortNumberCost.TOLL_FREE); Assert.Equal(ShortNumberInfo.ShortNumberCost.TOLL_FREE, ShortInfo.GetExpectedCostForRegion(Parse(tollFreeExample, RegionCode.FR), RegionCode.FR)); var tollFreeNumber = new PhoneNumber.Builder().SetCountryCode(33) .SetNationalNumber(ulong.Parse(tollFreeExample)).Build(); Assert.Equal(ShortNumberInfo.ShortNumberCost.TOLL_FREE, ShortInfo.GetExpectedCost(tollFreeNumber)); Assert.Equal(ShortNumberInfo.ShortNumberCost.UNKNOWN_COST, ShortInfo.GetExpectedCostForRegion(Parse("12345", RegionCode.FR), RegionCode.FR)); var unknownCostNumber = new PhoneNumber.Builder().SetCountryCode(33).SetNationalNumber(12345L); Assert.Equal(ShortNumberInfo.ShortNumberCost.UNKNOWN_COST, ShortInfo.GetExpectedCost(unknownCostNumber.Build())); // Test that an invalid number may nevertheless have a cost other than UNKNOWN_COST. Assert.False( ShortInfo.IsValidShortNumberForRegion(Parse("116123", RegionCode.FR), RegionCode.FR)); Assert.Equal(ShortNumberInfo.ShortNumberCost.TOLL_FREE, ShortInfo.GetExpectedCostForRegion(Parse("116123", RegionCode.FR), RegionCode.FR)); var invalidNumber = new PhoneNumber.Builder().SetCountryCode(33).SetNationalNumber(116123L).Build(); Assert.False(ShortInfo.IsValidShortNumber(invalidNumber)); Assert.Equal(ShortNumberInfo.ShortNumberCost.TOLL_FREE, ShortInfo.GetExpectedCost(invalidNumber)); // Test a nonexistent country code. Assert.Equal(ShortNumberInfo.ShortNumberCost.UNKNOWN_COST, ShortInfo.GetExpectedCostForRegion(Parse("911", RegionCode.US), RegionCode.ZZ)); unknownCostNumber.Clear(); unknownCostNumber.SetCountryCode(123).SetNationalNumber(911L); Assert.Equal(ShortNumberInfo.ShortNumberCost.UNKNOWN_COST, ShortInfo.GetExpectedCost(unknownCostNumber.Build())); }
public void TestSequences() { // Test multiple occurrences. String text = "Call 033316005 or 032316005!"; String region = "NZ"; PhoneNumber number1 = new PhoneNumber.Builder() .SetCountryCode(phoneUtil.GetCountryCodeForRegion(region)) .SetNationalNumber(33316005).Build(); PhoneNumberMatch match1 = new PhoneNumberMatch(5, "033316005", number1); PhoneNumber number2 = new PhoneNumber.Builder() .SetCountryCode(phoneUtil.GetCountryCodeForRegion(region)) .SetNationalNumber(32316005).Build(); PhoneNumberMatch match2 = new PhoneNumberMatch(19, "032316005", number2); var matches = phoneUtil.FindNumbers(text, region, PhoneNumberUtil.Leniency.POSSIBLE, long.MaxValue).GetEnumerator(); matches.MoveNext(); Assert.AreEqual(match1, matches.Current); matches.MoveNext(); Assert.AreEqual(match2, matches.Current); }
public void TestLookupNumberNotFound_TX() { var number = new PhoneNumber.Builder().SetCountryCode(1).SetNationalNumber(9724811234L).Build(); Assert.IsNull(areaCodeMapForUS.Lookup(number)); }
public void TestGetLengthOfNationalDestinationCode() { // Google MTV, which has national destination code (NDC) "650". Assert.AreEqual(3, phoneUtil.GetLengthOfNationalDestinationCode(US_NUMBER)); // A North America toll-free number, which has NDC "800". Assert.AreEqual(3, phoneUtil.GetLengthOfNationalDestinationCode(US_TOLLFREE)); // Google London, which has NDC "20". Assert.AreEqual(2, phoneUtil.GetLengthOfNationalDestinationCode(GB_NUMBER)); // A UK mobile phone, which has NDC "7912". Assert.AreEqual(4, phoneUtil.GetLengthOfNationalDestinationCode(GB_MOBILE)); // Google Buenos Aires, which has NDC "11". Assert.AreEqual(2, phoneUtil.GetLengthOfNationalDestinationCode(AR_NUMBER)); // An Argentinian mobile which has NDC "911". Assert.AreEqual(3, phoneUtil.GetLengthOfNationalDestinationCode(AR_MOBILE)); // Google Sydney, which has NDC "2". Assert.AreEqual(1, phoneUtil.GetLengthOfNationalDestinationCode(AU_NUMBER)); // Google Singapore, which has NDC "6521". Assert.AreEqual(4, phoneUtil.GetLengthOfNationalDestinationCode(SG_NUMBER)); // An invalid US number (1 digit shorter), which has no NDC. Assert.AreEqual(0, phoneUtil.GetLengthOfNationalDestinationCode(US_SHORT_BY_ONE_NUMBER)); // A number containing an invalid country calling code, which shouldn't have any NDC. PhoneNumber number = new PhoneNumber.Builder().SetCountryCode(123).SetNationalNumber(6502530000L).Build(); Assert.AreEqual(0, phoneUtil.GetLengthOfNationalDestinationCode(number)); }
public void TestFormatNumberForMobileDialing() { // US toll free numbers are marked as noInternationalDialling in the test metadata for testing // purposes. Assert.AreEqual("800 253 0000", phoneUtil.FormatNumberForMobileDialing(US_TOLLFREE, RegionCode.US, true /* keep formatting */)); Assert.AreEqual("", phoneUtil.FormatNumberForMobileDialing(US_TOLLFREE, RegionCode.CN, true)); Assert.AreEqual("+1 650 253 0000", phoneUtil.FormatNumberForMobileDialing(US_NUMBER, RegionCode.US, true)); PhoneNumber usNumberWithExtn = new PhoneNumber.Builder().MergeFrom(US_NUMBER).SetExtension("1234").Build(); Assert.AreEqual("+1 650 253 0000", phoneUtil.FormatNumberForMobileDialing(usNumberWithExtn, RegionCode.US, true)); Assert.AreEqual("8002530000", phoneUtil.FormatNumberForMobileDialing(US_TOLLFREE, RegionCode.US, false /* remove formatting */)); Assert.AreEqual("", phoneUtil.FormatNumberForMobileDialing(US_TOLLFREE, RegionCode.CN, false)); Assert.AreEqual("+16502530000", phoneUtil.FormatNumberForMobileDialing(US_NUMBER, RegionCode.US, false)); Assert.AreEqual("+16502530000", phoneUtil.FormatNumberForMobileDialing(usNumberWithExtn, RegionCode.US, false)); // An invalid US number, which is one digit too long. Assert.AreEqual("+165025300001", phoneUtil.FormatNumberForMobileDialing(US_LONG_NUMBER, RegionCode.US, false)); Assert.AreEqual("+1 65025300001", phoneUtil.FormatNumberForMobileDialing(US_LONG_NUMBER, RegionCode.US, true)); // Star numbers. In real life they appear in Israel, but we have them in JP in our test // metadata. Assert.AreEqual("*2345", phoneUtil.FormatNumberForMobileDialing(JP_STAR_NUMBER, RegionCode.JP, false)); Assert.AreEqual("*2345", phoneUtil.FormatNumberForMobileDialing(JP_STAR_NUMBER, RegionCode.JP, true)); Assert.AreEqual("+80012345678", phoneUtil.FormatNumberForMobileDialing(INTERNATIONAL_TOLL_FREE, RegionCode.JP, false)); Assert.AreEqual("+800 1234 5678", phoneUtil.FormatNumberForMobileDialing(INTERNATIONAL_TOLL_FREE, RegionCode.JP, true)); }
public void TestFormatWithPreferredCarrierCode() { // We only support this for AR in our test metadata. PhoneNumber arNumber = new PhoneNumber.Builder() .SetCountryCode(54).SetNationalNumber(91234125678L).Build(); // Test formatting with no preferred carrier code stored in the number itself. Assert.AreEqual("01234 15 12-5678", phoneUtil.FormatNationalNumberWithPreferredCarrierCode(arNumber, "15")); Assert.AreEqual("01234 12-5678", phoneUtil.FormatNationalNumberWithPreferredCarrierCode(arNumber, "")); // Test formatting with preferred carrier code present. arNumber = Update(arNumber).SetPreferredDomesticCarrierCode("19").Build(); Assert.AreEqual("01234 12-5678", phoneUtil.Format(arNumber, PhoneNumberFormat.NATIONAL)); Assert.AreEqual("01234 19 12-5678", phoneUtil.FormatNationalNumberWithPreferredCarrierCode(arNumber, "15")); Assert.AreEqual("01234 19 12-5678", phoneUtil.FormatNationalNumberWithPreferredCarrierCode(arNumber, "")); // When the preferred_domestic_carrier_code is present (even when it contains an empty string), // use it instead of the default carrier code passed in. arNumber = Update(arNumber).SetPreferredDomesticCarrierCode("").Build(); Assert.AreEqual("01234 12-5678", phoneUtil.FormatNationalNumberWithPreferredCarrierCode(arNumber, "15")); // We don't support this for the US so there should be no change. PhoneNumber usNumber = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(4241231234L).SetPreferredDomesticCarrierCode("99") .Build(); Assert.AreEqual("424 123 1234", phoneUtil.Format(usNumber, PhoneNumberFormat.NATIONAL)); Assert.AreEqual("424 123 1234", phoneUtil.FormatNationalNumberWithPreferredCarrierCode(usNumber, "15")); }
public void TestFormatWithCarrierCode() { // We only support this for AR in our test metadata, and only for mobile numbers starting with // certain values. PhoneNumber arMobile = new PhoneNumber.Builder().SetCountryCode(54).SetNationalNumber(92234654321L).Build(); Assert.AreEqual("02234 65-4321", phoneUtil.Format(arMobile, PhoneNumberFormat.NATIONAL)); // Here we force 14 as the carrier code. Assert.AreEqual("02234 14 65-4321", phoneUtil.FormatNationalNumberWithCarrierCode(arMobile, "14")); // Here we force the number to be shown with no carrier code. Assert.AreEqual("02234 65-4321", phoneUtil.FormatNationalNumberWithCarrierCode(arMobile, "")); // Here the international rule is used, so no carrier code should be present. Assert.AreEqual("+5492234654321", phoneUtil.Format(arMobile, PhoneNumberFormat.E164)); // We don't support this for the US so there should be no change. Assert.AreEqual("650 253 0000", phoneUtil.FormatNationalNumberWithCarrierCode(US_NUMBER, "15")); }
public void TestFormatOutOfCountryKeepingAlphaChars() { var alphaNumericNumber = new PhoneNumber.Builder() .SetCountryCode(1).SetNationalNumber(8007493524L) .SetRawInput("1800 six-flag") .Build(); Assert.AreEqual("0011 1 800 SIX-FLAG", phoneUtil.FormatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AU)); alphaNumericNumber = Update(alphaNumericNumber) .SetRawInput("1-800-SIX-flag") .Build(); Assert.AreEqual("0011 1 800-SIX-FLAG", phoneUtil.FormatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AU)); alphaNumericNumber = Update(alphaNumericNumber) .SetRawInput("Call us from UK: 00 1 800 SIX-flag") .Build(); Assert.AreEqual("0011 1 800 SIX-FLAG", phoneUtil.FormatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AU)); alphaNumericNumber = Update(alphaNumericNumber) .SetRawInput("800 SIX-flag") .Build(); Assert.AreEqual("0011 1 800 SIX-FLAG", phoneUtil.FormatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AU)); // Formatting from within the NANPA region. Assert.AreEqual("1 800 SIX-FLAG", phoneUtil.FormatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.US)); Assert.AreEqual("1 800 SIX-FLAG", phoneUtil.FormatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.BS)); // Testing that if the raw input doesn't exist, it is formatted using // FormatOutOfCountryCallingNumber. alphaNumericNumber = Update(alphaNumericNumber) .ClearRawInput() .Build(); Assert.AreEqual("00 1 800 749 3524", phoneUtil.FormatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.DE)); // Testing AU alpha number formatted from Australia. alphaNumericNumber = Update(alphaNumericNumber) .SetCountryCode(61).SetNationalNumber(827493524L) .SetRawInput("+61 82749-FLAG").Build(); alphaNumericNumber = Update(alphaNumericNumber).Build(); // This number should have the national prefix fixed. Assert.AreEqual("082749-FLAG", phoneUtil.FormatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AU)); alphaNumericNumber = Update(alphaNumericNumber) .SetRawInput("082749-FLAG").Build(); Assert.AreEqual("082749-FLAG", phoneUtil.FormatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AU)); alphaNumericNumber = Update(alphaNumericNumber) .SetNationalNumber(18007493524L).SetRawInput("1-800-SIX-flag").Build(); // This number should not have the national prefix prefixed, in accordance with the override for // this specific formatting rule. Assert.AreEqual("1-800-SIX-FLAG", phoneUtil.FormatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AU)); // The metadata should not be permanently changed, since we copied it before modifying patterns. // Here we check this. alphaNumericNumber = Update(alphaNumericNumber) .SetNationalNumber(1800749352L).Build(); Assert.AreEqual("1800 749 352", phoneUtil.FormatOutOfCountryCallingNumber(alphaNumericNumber, RegionCode.AU)); // Testing a region with multiple international prefixes. Assert.AreEqual("+61 1-800-SIX-FLAG", phoneUtil.FormatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.SG)); // Testing the case of calling from a non-supported region. Assert.AreEqual("+61 1-800-SIX-FLAG", phoneUtil.FormatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AQ)); // Testing the case with an invalid country calling code. alphaNumericNumber = Update(alphaNumericNumber) .SetCountryCode(0).SetNationalNumber(18007493524L).SetRawInput("1-800-SIX-flag").Build(); // Uses the raw input only. Assert.AreEqual("1-800-SIX-flag", phoneUtil.FormatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.DE)); // Testing the case of an invalid alpha number. alphaNumericNumber = Update(alphaNumericNumber) .SetCountryCode(1).SetNationalNumber(80749L).SetRawInput("180-SIX").Build(); // No country-code stripping can be done. Assert.AreEqual("00 1 180-SIX", phoneUtil.FormatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.DE)); // Testing the case of calling from a non-supported region. alphaNumericNumber = Update(alphaNumericNumber) .SetCountryCode(1).SetNationalNumber(80749L).SetRawInput("180-SIX").Build(); // No country-code stripping can be done since the number is invalid. Assert.AreEqual("+1 180-SIX", phoneUtil.FormatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AQ)); }
public void TestFormatDENumber() { var deNumber = new PhoneNumber.Builder().SetCountryCode(49).SetNationalNumber(301234L).Build(); Assert.AreEqual("030/1234", phoneUtil.Format(deNumber, PhoneNumberFormat.NATIONAL)); Assert.AreEqual("+49 30/1234", phoneUtil.Format(deNumber, PhoneNumberFormat.INTERNATIONAL)); Assert.AreEqual("tel:+49-30-1234", phoneUtil.Format(deNumber, PhoneNumberFormat.RFC3966)); deNumber = new PhoneNumber.Builder().SetCountryCode(49).SetNationalNumber(291123L).Build(); Assert.AreEqual("0291 123", phoneUtil.Format(deNumber, PhoneNumberFormat.NATIONAL)); Assert.AreEqual("+49 291 123", phoneUtil.Format(deNumber, PhoneNumberFormat.INTERNATIONAL)); deNumber = new PhoneNumber.Builder().SetCountryCode(49).SetNationalNumber(29112345678L).Build(); Assert.AreEqual("0291 12345678", phoneUtil.Format(deNumber, PhoneNumberFormat.NATIONAL)); Assert.AreEqual("+49 291 12345678", phoneUtil.Format(deNumber, PhoneNumberFormat.INTERNATIONAL)); deNumber = new PhoneNumber.Builder().SetCountryCode(49).SetNationalNumber(912312345L).Build(); Assert.AreEqual("09123 12345", phoneUtil.Format(deNumber, PhoneNumberFormat.NATIONAL)); Assert.AreEqual("+49 9123 12345", phoneUtil.Format(deNumber, PhoneNumberFormat.INTERNATIONAL)); deNumber = new PhoneNumber.Builder().SetCountryCode(49).SetNationalNumber(80212345L).Build(); Assert.AreEqual("08021 2345", phoneUtil.Format(deNumber, PhoneNumberFormat.NATIONAL)); Assert.AreEqual("+49 8021 2345", phoneUtil.Format(deNumber, PhoneNumberFormat.INTERNATIONAL)); // Note this number is correctly formatted without national prefix. Most of the numbers that // are treated as invalid numbers by the library are short numbers, and they are usually not // dialed with national prefix. Assert.AreEqual("1234", phoneUtil.Format(DE_SHORT_NUMBER, PhoneNumberFormat.NATIONAL)); Assert.AreEqual("+49 1234", phoneUtil.Format(DE_SHORT_NUMBER, PhoneNumberFormat.INTERNATIONAL)); deNumber = new PhoneNumber.Builder().SetCountryCode(49).SetNationalNumber(41341234).Build(); Assert.AreEqual("04134 1234", phoneUtil.Format(deNumber, PhoneNumberFormat.NATIONAL)); }
public void testFormatOutOfCountryCallingNumber() { Assert.AreEqual("00 1 900 253 0000", phoneUtil.FormatOutOfCountryCallingNumber(US_PREMIUM, RegionCode.DE)); Assert.AreEqual("1 650 253 0000", phoneUtil.FormatOutOfCountryCallingNumber(US_NUMBER, RegionCode.BS)); Assert.AreEqual("00 1 650 253 0000", phoneUtil.FormatOutOfCountryCallingNumber(US_NUMBER, RegionCode.PL)); Assert.AreEqual("011 44 7912 345 678", phoneUtil.FormatOutOfCountryCallingNumber(GB_MOBILE, RegionCode.US)); Assert.AreEqual("00 49 1234", phoneUtil.FormatOutOfCountryCallingNumber(DE_SHORT_NUMBER, RegionCode.GB)); // Note this number is correctly formatted without national prefix. Most of the numbers that // are treated as invalid numbers by the library are short numbers, and they are usually not // dialed with national prefix. Assert.AreEqual("1234", phoneUtil.FormatOutOfCountryCallingNumber(DE_SHORT_NUMBER, RegionCode.DE)); Assert.AreEqual("011 39 02 3661 8300", phoneUtil.FormatOutOfCountryCallingNumber(IT_NUMBER, RegionCode.US)); Assert.AreEqual("02 3661 8300", phoneUtil.FormatOutOfCountryCallingNumber(IT_NUMBER, RegionCode.IT)); Assert.AreEqual("+39 02 3661 8300", phoneUtil.FormatOutOfCountryCallingNumber(IT_NUMBER, RegionCode.SG)); Assert.AreEqual("6521 8000", phoneUtil.FormatOutOfCountryCallingNumber(SG_NUMBER, RegionCode.SG)); Assert.AreEqual("011 54 9 11 8765 4321", phoneUtil.FormatOutOfCountryCallingNumber(AR_MOBILE, RegionCode.US)); Assert.AreEqual("011 800 1234 5678", phoneUtil.FormatOutOfCountryCallingNumber(INTERNATIONAL_TOLL_FREE, RegionCode.US)); PhoneNumber arNumberWithExtn = new PhoneNumber.Builder().MergeFrom(AR_MOBILE).SetExtension("1234").Build(); Assert.AreEqual("011 54 9 11 8765 4321 ext. 1234", phoneUtil.FormatOutOfCountryCallingNumber(arNumberWithExtn, RegionCode.US)); Assert.AreEqual("0011 54 9 11 8765 4321 ext. 1234", phoneUtil.FormatOutOfCountryCallingNumber(arNumberWithExtn, RegionCode.AU)); Assert.AreEqual("011 15 8765-4321 ext. 1234", phoneUtil.FormatOutOfCountryCallingNumber(arNumberWithExtn, RegionCode.AR)); }
public void TestLookupNumber_NJ() { var number = new PhoneNumber.Builder().SetCountryCode(1).SetNationalNumber(2016641234L).Build(); Assert.AreEqual("Westwood, NJ", areaCodeMapForUS.Lookup(number)); }
public void TestFormatAUNumber() { Assert.AreEqual("02 3661 8300", phoneUtil.Format(AU_NUMBER, PhoneNumberFormat.NATIONAL)); Assert.AreEqual("+61 2 3661 8300", phoneUtil.Format(AU_NUMBER, PhoneNumberFormat.INTERNATIONAL)); Assert.AreEqual("+61236618300", phoneUtil.Format(AU_NUMBER, PhoneNumberFormat.E164)); PhoneNumber auNumber = new PhoneNumber.Builder().SetCountryCode(61).SetNationalNumber(1800123456L).Build(); Assert.AreEqual("1800 123 456", phoneUtil.Format(auNumber, PhoneNumberFormat.NATIONAL)); Assert.AreEqual("+61 1800 123 456", phoneUtil.Format(auNumber, PhoneNumberFormat.INTERNATIONAL)); Assert.AreEqual("+611800123456", phoneUtil.Format(auNumber, PhoneNumberFormat.E164)); }
public void TestLookupNumber_CA_1() { var number = new PhoneNumber.Builder().SetCountryCode(1).SetNationalNumber(6503451234L).Build(); Assert.AreEqual("San Mateo, CA", areaCodeMapForUS.Lookup(number)); }
public void TestIsNumberMatchMatches() { // Test simple matches where formatting is different, or leading zeroes, or country calling code // has been specified. Assert.AreEqual(PhoneNumberUtil.MatchType.EXACT_MATCH, phoneUtil.IsNumberMatch("+64 3 331 6005", "+64 03 331 6005")); Assert.AreEqual(PhoneNumberUtil.MatchType.EXACT_MATCH, phoneUtil.IsNumberMatch("+800 1234 5678", "+80012345678")); Assert.AreEqual(PhoneNumberUtil.MatchType.EXACT_MATCH, phoneUtil.IsNumberMatch("+64 03 331-6005", "+64 03331 6005")); Assert.AreEqual(PhoneNumberUtil.MatchType.EXACT_MATCH, phoneUtil.IsNumberMatch("+643 331-6005", "+64033316005")); Assert.AreEqual(PhoneNumberUtil.MatchType.EXACT_MATCH, phoneUtil.IsNumberMatch("+643 331-6005", "+6433316005")); Assert.AreEqual(PhoneNumberUtil.MatchType.EXACT_MATCH, phoneUtil.IsNumberMatch("+64 3 331-6005", "+6433316005")); Assert.AreEqual(PhoneNumberUtil.MatchType.EXACT_MATCH, phoneUtil.IsNumberMatch("+64 3 331-6005", "tel:+64-3-331-6005;isub=123")); // Test alpha numbers. Assert.AreEqual(PhoneNumberUtil.MatchType.EXACT_MATCH, phoneUtil.IsNumberMatch("+1800 siX-Flags", "+1 800 7493 5247")); // Test numbers with extensions. Assert.AreEqual(PhoneNumberUtil.MatchType.EXACT_MATCH, phoneUtil.IsNumberMatch("+64 3 331-6005 extn 1234", "+6433316005#1234")); // Test proto buffers. Assert.AreEqual(PhoneNumberUtil.MatchType.EXACT_MATCH, phoneUtil.IsNumberMatch(NZ_NUMBER, "+6403 331 6005")); PhoneNumber nzNumber = new PhoneNumber.Builder().MergeFrom(NZ_NUMBER).SetExtension("3456").Build(); Assert.AreEqual(PhoneNumberUtil.MatchType.EXACT_MATCH, phoneUtil.IsNumberMatch(nzNumber, "+643 331 6005 ext 3456")); // Check empty extensions are ignored. nzNumber = Update(nzNumber).SetExtension("").Build(); Assert.AreEqual(PhoneNumberUtil.MatchType.EXACT_MATCH, phoneUtil.IsNumberMatch(nzNumber, "+6403 331 6005")); // Check variant with two proto buffers. Assert.AreEqual( PhoneNumberUtil.MatchType.EXACT_MATCH, phoneUtil.IsNumberMatch(nzNumber, NZ_NUMBER), "Number " + nzNumber.ToString() + " did not match " + NZ_NUMBER.ToString()); // Check raw_input, country_code_source and preferred_domestic_carrier_code are ignored. PhoneNumber brNumberOne = new PhoneNumber.Builder() .SetCountryCode(55).SetNationalNumber(3121286979L) .SetCountryCodeSource(PhoneNumber.Types.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN) .SetPreferredDomesticCarrierCode("12").SetRawInput("012 3121286979").Build(); PhoneNumber brNumberTwo = new PhoneNumber.Builder() .SetCountryCode(55).SetNationalNumber(3121286979L) .SetCountryCodeSource(PhoneNumber.Types.CountryCodeSource.FROM_DEFAULT_COUNTRY) .SetPreferredDomesticCarrierCode("14").SetRawInput("143121286979").Build(); Assert.AreEqual(PhoneNumberUtil.MatchType.EXACT_MATCH, phoneUtil.IsNumberMatch(brNumberOne, brNumberTwo)); }