用正则表达式判断是不是正确的IP地址的代码
/// <summary>
/// 判断是否是Ip地址
/// </summary>
/// <param name="str1"></param>
/// <returns></returns>
public static bool IsIPAddress(string str1)
{
if (str1 == null || str1 == string.Empty || str1.Length < 7 || str1.Length > 15) return false;
string regformat = @"^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$";
Regex regex = new Regex(regformat, RegexOptions.IgnoreCase);
return regex.IsMatch(str1);
}
浙公网安备 33010602011771号