使用正则表达式

        public static bool IsIPv4Address(string ip) {
            
string pattern = @"^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$";
            Regex r 
= new Regex(pattern);
            Match m 
= r.Match(ip);

            
return m.Success;
        }
posted on 2008-09-01 13:27  ю意思я  阅读(625)  评论(0编辑  收藏  举报