---
title: "A libphonenumber C# alternative: OneContact"
url: https://recursiveai.org/onecontact/articles/migrate-from-libphonenumber-csharp/
description: "Replace libphonenumber-csharp parsing, validation, and formatting with OneContact. See both packages run and learn what to regression-test."
date: 2026-11-29
author: OneContact team
---

# A libphonenumber C# alternative: OneContact

Replace libphonenumber-csharp parsing, validation, and formatting with OneContact. See both packages run and learn what to regression-test.

November 29, 2026 · OneContact team

OneContact uses an immutable `PhoneNumber` instead of `PhoneNumberUtil`.

OneContact is a free, open-source contact-data library for .NET from Recursive AI, licensed MIT OR Apache-2.0. [NuGet](https://www.nuget.org/packages/RecursiveAI.OneContact/1.0.0) · [GitHub](https://github.com/recursive-ai-oss/onecontact-csharp).

*Install · NuGet*

```
dotnet add package RecursiveAI.OneContact --version 1.0.0
```

*Program.cs · OneContact · .NET 10*

```
using RecursiveAI.OneContact;
using RecursiveAI.OneContact.Phones;
 
foreach (var (text, region) in new (string, Region?)[]
{
    ("(415) 555-2671", Region.US),
    ("+1 415 555 2671", null),
    ("+1 123 456 7890", null),
    ("not a number", Region.US),
})
{
    try
    {
        var number = region is Region r
            ? PhoneNumber.Parse(text, r)
            : PhoneNumber.Parse(text);
        Console.WriteLine($"{number.IsValid} | " +
            $"{number.Format(PhoneFormat.E164)} | " +
            $"{number.Format(PhoneFormat.National)}");
    }
    catch (ContactParseException e)
    {
        Console.WriteLine($"Parse failed: {e.Reason}");
    }
}
```

Run the OneContact example above in a .NET 10 console project. It prints validity, E.164, and national format for national and international US input, then tests an invalid number and unreadable text.

*Output · OneContact 1.0.0*

```
True | +14155552671 | (415) 555-2671
True | +14155552671 | (415) 555-2671
False | +11234567890 | 1234567890
Parse failed: phone.not-a-number
```

## Before: libphonenumber-csharp 9.0.44

Run this version in a separate .NET 10 console project. The port’s [NuGet README](https://www.nuget.org/packages/libphonenumber-csharp/9.0.44#readme-body-tab) documents `PhoneNumberUtil.GetInstance()`, region strings for national input, and `null` for `+`-prefixed input.

*Install · NuGet*

```
dotnet add package libphonenumber-csharp --version 9.0.44
```

*Program.cs · libphonenumber-csharp · .NET 10*

```
using PhoneNumbers;
 
var util = PhoneNumberUtil.GetInstance();
foreach (var (text, region) in new (string, string?)[]
{
    ("(415) 555-2671", "US"),
    ("+1 415 555 2671", null),
    ("+1 123 456 7890", null),
    ("not a number", "US"),
})
{
    try
    {
        var number = util.Parse(text, region);
        Console.WriteLine($"{util.IsValidNumber(number)} | " +
            $"{util.Format(number, PhoneNumberFormat.E164)} | " +
            $"{util.Format(number, PhoneNumberFormat.NATIONAL)}");
    }
    catch (NumberParseException e)
    {
        Console.WriteLine($"Parse failed: {e.ErrorType}");
    }
}
```

*Output · libphonenumber-csharp 9.0.44*

```
True | +14155552671 | (415) 555-2671
True | +14155552671 | (415) 555-2671
False | +11234567890 | 1234567890
Parse failed: NOT_A_NUMBER
```

## Call mapping

These mappings use the [port’s API docs](https://twcclegg.github.io/libphonenumber-csharp/docs/) and the [OneContact migration reference](https://recursiveai.org/onecontact/docs/migrating/). `number` means the result from that column’s parser.

| Task | libphonenumber-csharp | OneContact |
|---|---|---|
| Parse US national input | `util.Parse(text, "US")` | `PhoneNumber.Parse(text, Region.US)` |
| Parse international input starting with + | `util.Parse(text, null)` | `PhoneNumber.Parse(text)` |
| Check numbering-plan validity | `util.IsValidNumber(number)` | `number.IsValid` |
| Format for storage | `util.Format(number, PhoneNumberFormat.E164)` | `number.Format(PhoneFormat.E164)` |
| Format for local display | `util.Format(number, PhoneNumberFormat.NATIONAL)` | `number.Format(PhoneFormat.National)` |
| Format for international display | `util.Format(number, PhoneNumberFormat.INTERNATIONAL)` | `number.Format(PhoneFormat.International)` |
| Read a parse failure | `NumberParseException.ErrorType` | `ContactParseException.Reason`; translate to your own error categories |

Use `Region.Parse(countryCode)` for an ISO region string instead of passing that string to the parser. Keep region selection at the input boundary rather than inferring it from the machine’s locale.

## Regression checklist

- **National versus international:** Test each supported region’s national input, its `+`-prefixed equivalent without a region, and national input with the region omitted. OneContact reports `phone.region-required` for national input with no region. Test region-specific dialing prefixes separately from `+` input.
- **Parse failure versus invalid number:** Include unreadable text and a parseable but invalid number. In the output above, both parsers can format the invalid number; that does not make it valid, let alone reachable. Translate the two libraries’ errors at your application boundary instead of matching exception messages.
- **Formatting and stored data:** Compare E.164 and display strings on your own fixtures, including extensions and leading zeros if you store them. Do not overwrite old records until you know which output changes your app can accept.
- **Metadata changes:** Record both package versions with the baseline results. The port’s [README](https://www.nuget.org/packages/libphonenumber-csharp/9.0.44#readme-body-tab) describes frequent upstream metadata updates. [OneContact](https://recursiveai.org/onecontact/docs/migrating/) bundles numbering-plan data from a pinned libphonenumber release and ships newer data in patch releases. Rerun your fixture set when either package changes and review validity and formatting differences rather than treating every change as a parser bug.

If your app also finds numbers in free text or formats them as users type, test those separately using the [phone API reference](https://recursiveai.org/onecontact/docs/phones/). The agreement above covers the four inputs shown, not every operation or numbering plan.
