Table of Contents

Class AsYouTypeFormatter

Namespace
PhoneNumbers
Assembly
PhoneNumbers.dll

A formatter which formats phone numbers as they are entered.

An AsYouTypeFormatter can be created by invoking GetAsYouTypeFormatter(string). After that, digits can be added by invoking InputDigit(char) on the formatter instance, and the partially formatted phone number will be returned each time a digit is added. {@link #clear} can be invoked before formatting a new number.

See the unittests for more details on how the formatter is to be used.

public class AsYouTypeFormatter
Inheritance
AsYouTypeFormatter
Inherited Members

Constructors

AsYouTypeFormatter(string, PhoneNumberUtil)

Constructs an as-you-type formatter. Should be obtained from GetAsYouTypeFormatter(string).

public AsYouTypeFormatter(string regionCode, PhoneNumberUtil phoneUtil)

Parameters

regionCode string

The country/region where the phone number is being entered.

phoneUtil PhoneNumberUtil

Methods

Clear()

Clears the internal state of the formatter, so it can be reused.

public void Clear()

GetRememberedPosition()

Returns the current position in the partially formatted phone number of the character which was previously passed in as the parameter of {@link #inputDigitAndRememberPosition}.

public int GetRememberedPosition()

Returns

int

InputDigit(char)

Formats a phone number on-the-fly as each digit is entered.

public string InputDigit(char nextChar)

Parameters

nextChar char

The most recently entered digit of a phone number. Formatting characters are allowed, but as soon as they are encountered this method formats the number as entered and not "as you type" anymore. Full width digits and Arabic-indic digits are allowed, and will be shown as they are.

Returns

string

The partially formatted phone number.

InputDigitAndRememberPosition(char)

Same as InputDigit(char), but remembers the position where nextChar is inserted, so that it can be retrieved later by using GetRememberedPosition(). The remembered position will be automatically adjusted if additional formatting characters are later inserted/removed in front of nextChar.

public string InputDigitAndRememberPosition(char nextChar)

Parameters

nextChar char

Returns

string