实现效果:

  使用正则表达式验证IP地址

知识运用:

  使用正则表达式验证IP地址

实现代码:

        public bool validate(string str_IP) {
            string regex = @"(25[0-5]|2[0-4]\d|[0-1]\d{2}|[0-9]?\d)";
            return Regex.IsMatch(textBox1.Text,("^"+regex+"\\."+regex+"\\."+regex+"\\."+regex+"$"));
        }

 

相关文章: