Recursive AI

Tell whether a phone number is mobile or landline 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.

Parse an international number and read its line type from the region’s numbering plan. This doesn’t look up the subscriber or verify service.

Terminal
dotnet add package RecursiveAI.OneContact

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using RecursiveAI.OneContact;
 
foreach (var input in new[] {
    "+61491570006", "+442079460123" })
    Console.WriteLine(PhoneNumber.Parse(input).Type);

The example is the full program below: unzip it and dotnet run. To run only the code above, paste it into Program.cs of a new dotnet new console project and dotnet run.

Text
Mobile
FixedLine

The full program

C#
using RecursiveAI.OneContact;
 
string[] inputs = ["+61491570006", "+442079460123",
    "+12025550123", "+12001230123"];
foreach (string input in inputs)
{
    if (!PhoneNumber.TryParse(input, out var phone))
    {
        Console.WriteLine($"{input}: cannot parse");
        continue;
    }
    string type = phone.Type switch
    {
        PhoneNumberType.Mobile => "mobile",
        PhoneNumberType.FixedLine => "landline",
        PhoneNumberType.FixedLineOrMobile => "either",
        PhoneNumberType.Unknown => "unknown",
        _ => phone.Type.ToString()
    };
    Console.WriteLine($"{input}: {type}");
}

dotnet run prints:

Text
+61491570006: mobile
+442079460123: landline
+12025550123: either
+12001230123: unknown

TryParse handles text the parser rejects. A successful parse can still produce Unknown, as the last row shows. either means the regional numbering plan does not distinguish fixed and mobile for that number; it does not mean OneContact verified both.

Variations

For a national number, supply the region explicitly. Add these lines to the full program:

C#
var local = PhoneNumber.Parse("020 7946 0123",
    Region.Parse("GB"));
Console.WriteLine($"{local.E164}: {local.Type}");
Text
+442079460123: FixedLine

The short answer

Parse the number and read PhoneNumber.Type. FixedLine means landline and Mobile means mobile in the regional numbering data. Keep FixedLineOrMobile, Unknown, and any other types as separate results. Don’t turn every non-mobile result into a landline.

Is there a way to determine if a phone number is a landline or mobile?

Yes, when the numbering plan identifies one type for the number pattern. Pass the complete international form including + and the calling code. For local-format input, give the parser the region as in Variations: without it, the parser cannot read a national string as a national number. Use the number’s region, not a server locale that happens to be set on the machine running the code. See the phone parsing rules.

A single number can match a pattern that the plan uses for both fixed and mobile lines. In the full example, +12025550123 gives FixedLineOrMobile. Keep that outcome ambiguous. Unknown is different: the input parsed, but the number did not match a known type. This can happen even when the length and calling code allow the string to be parsed. A parse failure, such as missing its calling code when there is no default region, is a separate case again.

Does phone number validation verify the owner?

No. The library classifies number patterns, not people. Type doesn’t query a carrier; it can’t tell you whether a number is assigned, who controls it, or whether a message would be delivered. OneContact’s IsValid checks for a known numbering-plan type, so a result can be valid by that test and still be ambiguous between fixed and mobile. The Australian mobile example uses a number reserved for fiction.

If the user needs to confirm control of a number, make that a separate verification step in your application. Use this classification for cases where a plan-based result is enough, such as labeling phone fields for review. If a workflow needs definite mobile status, an ambiguous result is not permission to proceed as if the number had been verified.

All onecontact recipes