LogoReturn to Home RegEx
Integrations
All integrations
AWS API
AWS Lambda
DynamoDB
Oracle
Redshift
Snowflake
GraphQL
Supabase
Twilio
Azure Blob Storage
Slack
SendGrid
Generic HTTP API
AWS S3
Stripe
Microsoft SQL
Salesforce
PostgreSQL
MySQL
MongoDB
HubSpot
Google Sheets
Google BigQuery
Firebase
Airtable
Integrations
About UI Bakery
Log in
Request UI Bakery demo
RegEx library
Email regex C#
Phone number regex C#
IP address regex C#
Date regex C#
URL regex C#
Numbers only regex (digits only) C#
UUID regex C#
Regex match words C#
ZIP code regex C#
GUID regex C#
Password regex C#
HTML regex C#
SSN regex C#
XML regex C#
Mac address regex C#
Street address regex C#

Phone number regex C#

The regular expressions below can be used to validate if a string is a valid phone number format and to extract a phone number from a string. Please note that this validation can not tell if a phone number actually exists.

Discover UI Bakery – an intuitive visual internal tools builder. Try it now!
JavaScript
Python
Java
C#
PHP

The basic international phone number validation

A simple regex to validate string against a valid international phone number format without delimiters and with an optional plus sign:

new Regex("^\\+?[1-9][0-9]{7,14}$")
Test it!
/^\+?[1-9][0-9]{7,14}$/

True

False

Enter a text in the input above to see the result

Example code in C#:

using System.Text.RegularExpressions;
using System.Linq;
                    
public class Program
{
    public static void Main()
    {
        // Validate phone number
        Regex validatePhoneNumberRegex = new Regex("^\\+?[1-9][0-9]{7,14}$");
        validatePhoneNumberRegex.IsMatch("+12223334444"); // returns True
        
        // Extract phone number from a string
        Regex extractPhoneNumberRegex = new Regex("\\+?[1-9][0-9]{7,14}");
        extractPhoneNumberRegex.Matches("You can reach me out at +12223334444 and +56667778888")
            .Cast<Match>()
            .Select(m => m.Value) 
            .ToArray(); // returns {"+12223334444", "+56667778888"}
    }
}

The more complex phone number validation

This regular expression will match phone numbers entered with delimiters (spaces, dots, brackets, etc.)

new Regex("^\\+?\\d{1,4}?[-.\\s]?\\(?\\d{1,3}?\\)?[-.\\s]?\\d{1,4}[-.\\s]?\\d{1,4}[-.\\s]?\\d{1,9}$")
Test it!
/^\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}$/

True

False

Enter a text in the input above to see the result

Example code in C#:

using System.Text.RegularExpressions;
                    
public class Program
{
    public static void Main()
    {
        // Validate phone number
        Regex validatePhoneNumberRegex = new Regex("^\\+?\\d{1,4}?[-.\\s]?\\(?\\d{1,3}?\\)?[-.\\s]?\\d{1,4}[-.\\s]?\\d{1,4}[-.\\s]?\\d{1,9}$");
        validatePhoneNumberRegex.IsMatch("+1 (615) 243-5172"); // returns True
    }
}
Test it!

True

False

Enter a text in the input above to see the result

Extra information about validating phone number

While validation of phone numbers using regex can give a possibility to check the format of the phone number, it does not guarantee that the number exists.

There might be also an option to leave a phone number field without any validation since some users might have:

  • More complex phone numbers with extensions
  • The different phone numbers for calling them on a different time of day

Create an internal tool with UI Bakery

Discover UI Bakery – an intuitive visual internal tools builder.

Try it now