Table of Contents

Class PhoneNumberMatcher

Namespace
PhoneNumbers
Assembly
PhoneNumbers.dll

The phone number pattern used by {@link #find}, similar to PhoneNumberUtil.VALID_PHONE_NUMBER, but with the following differences:

  • All captures are limited in order to place an upper bound to the text matched by the pattern.
  • Leading punctuation / plus signs are limited.
  • Consecutive occurrences of punctuation are limited.
  • Number of digits is limited.
  • No whitespace is allowed at the start or end.
  • No alpha digits (vanity numbers such as 1-800-SIX-FLAGS) are currently supported.
public class PhoneNumberMatcher : IEnumerator<PhoneNumberMatch>, IEnumerator, IDisposable
Inheritance
PhoneNumberMatcher
Implements
Inherited Members

Constructors

PhoneNumberMatcher(PhoneNumberUtil, string, string, Leniency, long)

Creates a new instance. See the factory methods in {@link PhoneNumberUtil} on how to obtain a new instance.

public PhoneNumberMatcher(PhoneNumberUtil util, string text, string country, PhoneNumberUtil.Leniency leniency, long maxTries)

Parameters

util PhoneNumberUtil

the phone number util to use

text string

the character sequence that we will search, null for no text

country string

the country to assume for phone numbers not written in international format (with a leading plus, or with the international dialing prefix of the specified region). May be null or "ZZ" if only numbers with a leading plus should be considered.

leniency PhoneNumberUtil.Leniency

the leniency to use when evaluating candidate phone numbers

maxTries long

the maximum number of invalid numbers to try before giving up on the text. This is to cover degenerate cases where the text has a lot of false positives in it. Must be >= 0.

Properties

Current

Gets the element in the collection at the current position of the enumerator.

public PhoneNumberMatch Current { get; }

Property Value

PhoneNumberMatch

The element in the collection at the current position of the enumerator.

Methods

AllNumberGroupsAreExactlyPresent(PhoneNumberUtil, PhoneNumber, StringBuilder, IList<string>)

public static bool AllNumberGroupsAreExactlyPresent(PhoneNumberUtil util, PhoneNumber number, StringBuilder normalizedCandidate, IList<string> formattedNumberGroups)

Parameters

util PhoneNumberUtil
number PhoneNumber
normalizedCandidate StringBuilder
formattedNumberGroups IList<string>

Returns

bool

AllNumberGroupsRemainGrouped(PhoneNumberUtil, PhoneNumber, StringBuilder, IList<string>)

public static bool AllNumberGroupsRemainGrouped(PhoneNumberUtil util, PhoneNumber number, StringBuilder normalizedCandidate, IList<string> formattedNumberGroups)

Parameters

util PhoneNumberUtil
number PhoneNumber
normalizedCandidate StringBuilder
formattedNumberGroups IList<string>

Returns

bool

CheckNumberGroupingIsValid(PhoneNumber, string, PhoneNumberUtil, CheckGroups)

public bool CheckNumberGroupingIsValid(PhoneNumber number, string candidate, PhoneNumberUtil util, PhoneNumberMatcher.CheckGroups checker)

Parameters

number PhoneNumber
candidate string
util PhoneNumberUtil
checker PhoneNumberMatcher.CheckGroups

Returns

bool

ContainsMoreThanOneSlash(PhoneNumber, string)

public static bool ContainsMoreThanOneSlash(PhoneNumber number, string candidate)

Parameters

number PhoneNumber
candidate string

Returns

bool

ContainsMoreThanOneSlash(string)

Preserved for binary/source compatibility with the public API shipped before the country-code-aware overload below was introduced. New callers should prefer ContainsMoreThanOneSlash(PhoneNumber, string), which matches upstream Java's more precise handling of slashes that fall within the country calling code prefix.

public static bool ContainsMoreThanOneSlash(string candidate)

Parameters

candidate string

Returns

bool

ContainsOnlyValidXChars(PhoneNumber, string, PhoneNumberUtil)

public static bool ContainsOnlyValidXChars(PhoneNumber number, string candidate, PhoneNumberUtil util)

Parameters

number PhoneNumber
candidate string
util PhoneNumberUtil

Returns

bool

IsLatinLetter(char)

Helper method to determine if a character is a Latin-script letter or not. For our purposes, combining marks should also return true since we assume they have been added to a preceding Latin character.

public static bool IsLatinLetter(char letter)

Parameters

letter char

Returns

bool

IsNationalPrefixPresentIfRequired(PhoneNumber, PhoneNumberUtil)

public static bool IsNationalPrefixPresentIfRequired(PhoneNumber number, PhoneNumberUtil util)

Parameters

number PhoneNumber
util PhoneNumberUtil

Returns

bool

MoveNext()

Advances the enumerator to the next element of the collection.

public bool MoveNext()

Returns

bool

true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.

Exceptions

InvalidOperationException

The collection was modified after the enumerator was created.

Reset()

Sets the enumerator to its initial position, which is before the first element in the collection.

public void Reset()

Exceptions

InvalidOperationException

The collection was modified after the enumerator was created.

NotSupportedException

The enumerator does not support being reset.

TrimAfterUnwantedChars(string)

public static string TrimAfterUnwantedChars(string str)

Parameters

str string

Returns

string