Checks if a given string is a valid IP address.
using System;
using System.Text.RegularExpressions;
namespace BuildScreen.Core.Utilities
{
public static class Validation
{
/// <summary>
/// Checks if a given string is a valid IP address.
/// </summary>
/// <param name="value">The string to be checked.</param>
/// <returns>A boolean value.</returns>
public static bool IsIPv4(string value)
{
if (string.IsNullOrEmpty(value))
return false;
Regex regex = new Regex(@"^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
return regex.IsMatch(value);
}
}
}
Related examples in the same category