PhoneNumberFormatter.FormatPartialString(String) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
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 FormatPartialString | Formatted output |
---|---|
1 | 1 |
14 | 14 |
142 | 142 |
1425 | 1 425 |
1425555 | 1 425-555 |
14255558 | 1 425-555-8 |
14255558080 | 1 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);
}