Is IP Address by Regex - CSharp System.Text.RegularExpressions

CSharp examples for System.Text.RegularExpressions:Match IP Address

Description

Is IP Address by Regex

Demo Code


using System.Text.RegularExpressions;

public class Main{
        public static bool IsIPAddress(string input)
        {/* w w  w . j a  v  a 2s . c  om*/
            if (string.IsNullOrEmpty(input) || input.Length < 7 || input.Length > 15)
                return false;

            Regex regex = new Regex(@"^([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])\.([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])\.([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])\.([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])$", RegexOptions.IgnoreCase);
            return regex.IsMatch(input);
        }
}

Related Tutorials