C#端口、IP正则
端口正则: string pattrn = "^[0-9]+$"; if (System.Text.RegularExpressions.Regex.IsMatch(PorttextBox.Text.Trim(), pattrn)){}; IP正则: string _pattrn = @"(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])"; if (System.Text.RegularExpressions.Regex.IsMatch(this.IptextBox.Text, _pattrn)){}; 来源: https://www.cnblogs.com/LCLBook/p/11724378.html