Dela via


PhoneNumberFormatter.FormatPartialString(String) Method

Definition

Returns a string representing the formatted partial phone number given.

Use this method to format phone numbers as they are being entered by a user, to help the user visualize the complete, formatted number.

public:
 virtual Platform::String ^ FormatPartialString(Platform::String ^ number) = FormatPartialString;
winrt::hstring FormatPartialString(winrt::hstring const& number);
public string FormatPartialString(string number);
function formatPartialString(number)
Public Function FormatPartialString (number As String) As String

Parameters

number
String

Platform::String

winrt::hstring

A string representing a partial phone number.

Returns

String

Platform::String

winrt::hstring

The input string, formatted as a partial phone number.

Remarks

The following table shows the results of repeatedly calling this method as a user enters digits from a phone number, using a formatter set to the "US" region.

Digits passed to FormatPartialStringFormatted output
11
1414
142142
14251 425
14255551 425-555
142555581 425-555-8
142555580801 425-555-8080

The following code snippet demonstrates a TextChanged event handler that updates a TextBlock with the formatted partial number whenever the number typed into the event handler's TextBox changes.

using Windows.Globalization.PhoneNumberFormatting;

PhoneNumberFormatter currentFormatter;

public MainPage()
{
    this.InitializeComponent();

    // Using the current default region
    currentFormatter = new PhoneNumberFormatter();
}

private void gradualInput_TextChanged(object sender, TextChangedEventArgs e)
{
    outBlock.Text = currentFormatter.FormatPartialString(gradualInput.Text);
}

Applies to