C# Regex 2019, Jul 26 C# implementation of regex to check if parameter is a valid IP address. using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; public class Program { public static string CheckValidIP(string ipaddress) { string pattern = @"^((25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})$"; Match result = Regex.Match(ipaddress, pattern); if (result.Success) { return result.Value.ToString(); } else { return "Not Valid IP!"; } } public static void Main(string[] args) { Console.WriteLine(CheckValidIP("255.48.8.29")); Console.WriteLine(CheckValidIP("999.48.8.29")); } } Ian Fogelman My name is Ian Fogelman. I like to develop data driven solutions with SQL Server, Python, .NET and predictive analytics. Recent post Syncing an Entire S3 bucket to local Database Collations in Different RDMS Snowflake Tasks Managing Conda Environments for Jupyter Notebooks Newsletter Subscribe here to get our latest updates Email Address Please enable JavaScript to view the comments powered by Disqus.