public IsNumberMatch ( |
||
firstNumberIn | ||
secondNumberIn | ||
return | MatchType |
/// <summary> /// Checks whether 2 phone numbers of the same region are valid and equal. /// </summary> /// <param name="number1"></param> /// <param name="number2"></param> /// <param name="defaultRegion"></param> /// <returns>Returns true, if the phone numbers are valid and equal, else false.</returns> public bool IsMatch(string number1, string number2, string defaultRegion) { if (!IsValid(number1, defaultRegion) || !IsValid(number2, defaultRegion)) { return(false); } lock (Locker) { return(_fnu.IsNumberMatch(_fnu.Parse(number1, defaultRegion), _fnu.Parse(number2, defaultRegion)) == PhoneNumberUtil.MatchType.EXACT_MATCH); } }
internal static bool ContainsOnlyValidXChars( PhoneNumber number, String candidate, PhoneNumberUtil util) { // The characters 'x' and 'X' can be (1) a carrier code, in which case they always precede the // national significant number or (2) an extension sign, in which case they always precede the // extension number. We assume a carrier code is more than 1 digit, so the first case has to // have more than 1 consecutive 'x' or 'X', whereas the second case can only have exactly 1 // 'x' or 'X'. We ignore the character if it appears as the last character of the string. for (int index = 0; index < candidate.Length - 1; index++) { char charAtIndex = candidate[index]; if (charAtIndex == 'x' || charAtIndex == 'X') { char charAtNextIndex = candidate[index + 1]; if (charAtNextIndex == 'x' || charAtNextIndex == 'X') { // This is the carrier code case, in which the 'X's always precede the national // significant number. index++; if (util.IsNumberMatch(number, candidate.Substring(index)) != MatchType.NSN_MATCH) { return false; } // This is the extension sign case, in which the 'x' or 'X' should always precede the // extension number. } else if (!PhoneNumberUtil.NormalizeDigitsOnly(candidate.Substring(index)).Equals( number.Extension)) { return false; } } } return true; }