public static bool IsIP(string ip)
{
//判断是否为IP
return Regex.IsMatch(ip, @"^((2[0-4]/d|25[0-5]|[01]?/d/d?)/.){3}(2[0-4]/d|25[0-5]|[01]?/d/d?)$");
}
IP的正则表达式:
匹配ip地址:/d+/./d+/./d+/./d+
评注:提取ip地址时有用
本文介绍了一种使用C#中的正则表达式来验证IP地址有效性的方法。通过一个静态公共函数IsIP,可以检查传入的字符串是否符合IPv4地址的标准格式。
public static bool IsIP(string ip)
{
//判断是否为IP
return Regex.IsMatch(ip, @"^((2[0-4]/d|25[0-5]|[01]?/d/d?)/.){3}(2[0-4]/d|25[0-5]|[01]?/d/d?)$");
}
IP的正则表达式:
匹配ip地址:/d+/./d+/./d+/./d+
评注:提取ip地址时有用

被折叠的 条评论
为什么被折叠?