---
title: "Convert a vanity phone number to digits in C#"
url: https://recursiveai.org/onecontact/cookbook/convert-vanity-phone-number-to-digits/
description: "Convert 1-800-FLOWERS to +18003569377 in C#. Use a US region hint and check the vanity flag when you normalize a phone number with letters."
version: "1.0.0"
---

# Convert a vanity phone number to digits in C#

**OneContact** is a free, open-source contact data library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies, no network access.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneContact) · [GitHub](https://github.com/recursive-ai-oss/onecontact-csharp) · [Docs](https://recursiveai.org/onecontact/docs/) · [Download example (.zip)](https://recursiveai.org/onecontact/cookbook/convert-vanity-phone-number-to-digits/convert-vanity-phone-number-to-digits.zip)

A vanity number spells a word with keypad letters, so `1-800-FLOWERS` is `1-800-356-9377`.

```shell
dotnet add package RecursiveAI.OneContact
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OneContact;
var phone = PhoneNumber.Parse(
    "1-800-FLOWERS", Region.US);
Console.WriteLine(phone.E164);
bool vanity = phone.Flags
    .HasFlag(PhoneFacts.Vanity);
Console.WriteLine($"Vanity: {vanity}");
```

Unzip [the example](https://recursiveai.org/onecontact/cookbook/convert-vanity-phone-number-to-digits/convert-vanity-phone-number-to-digits.zip), then `dotnet run`.

Prints the international number and whether the input was a vanity number:

```text
+18003569377
Vanity: True
```

`Region.US` tells the parser how to interpret the number without a leading `+`. If the text can’t be parsed, `Parse` throws `ContactParseException`; use `TryParse` for a phone number entered in a form.

## Variations

**Take an international number without a region hint.** Replace the `Parse` call with this one. The leading `+1` supplies the calling code, and lowercase letters give the same output.

```csharp
var phone = PhoneNumber.Parse("+1-800-flowers");
```

## Related recipes

- [Format a phone number in E.164](https://recursiveai.org/onecontact/cookbook/format-phone-number-e164/)
- [Validate a phone number](https://recursiveai.org/onecontact/cookbook/validate-phone-number/)

## The short answer

Pass `1-800-FLOWERS` and `Region.US` to `PhoneNumber.Parse`. Read `E164` to get `+18003569377`, a `+` followed by the country calling code and the national number, without separators. Read `PhoneFacts.Vanity` if you need to know whether the original text was a vanity number. The all-digit form of the same number has the same `E164` string but does not have the vanity flag.

## How do I convert letters to numbers on a phone keypad?

A [phone keypad maps letters in groups](https://dev.to/realedwintorres/an-algorithm-to-translate-vanity-phone-numbers-29bg): `ABC` to `2`, `DEF` to `3`, `GHI` to `4`, `JKL` to `5`, `MNO` to `6`, `PQRS` to `7`, `TUV` to `8`, and `WXYZ` to `9`. Read `FLOWERS` from left to right: `F` is `3`, `L` is `5`, `O` is `6`, `W` is `9`, `E` is `3`, `R` is `7`, and `S` is `7`. That gives `3569377`.

OneContact’s [phone parser](https://recursiveai.org/onecontact/docs/phones/#parsing) converts letters to keypad digits when the phone number contains at least three ASCII letters. It reads `ext` before an extension number as a marker, not as part of the phone number. This is why globally replacing every letter in a contact field with a digit is not equivalent to parsing a phone number: it would turn part of the extension marker into part of the number.

## How do I format a vanity phone number internationally in C#?

Use `E164` for the international number and keep the original spelling separately if you want to display `1-800-FLOWERS` to users. The digits cannot tell you which letters were supplied: `3` could have come from `D`, `E`, or `F`, or have been a digit all along. The vanity flag records how the number was entered, not whether the number can receive a call.

For input without `+` and a calling code, use the country or region the user selected. Without a hint, OneContact refuses national input rather than assuming it is American. If you accept extensions, keep `Extension` separately or read `Canonical`, which appends it as `;ext=…`. `E164` as printed above omits the extension.
