CSharp examples for System.Text.RegularExpressions:Match IP Address
Is IP Address by Regex
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); } }