使用正则表达式验证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+"$"));
        }

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/10053539.html