验证ip地址

/// <summary>
/// 验证ip地址
/// </summary>
/// <param name="ipAddress"></param>
/// <returns></returns>
public static bool ValidateIPAddress(string ipAddress)
{
//https://blog.csdn.net/linxinfa/article/details/99306256
Regex validipregex = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$");
return (ipAddress != "" && validipregex.IsMatch(ipAddress.Trim())) ? true : false;
}

posted @ 2022-07-27 09:05  .net&new  阅读(45)  评论(0编辑  收藏  举报