如下的代码是关于C#验证ip地址的代码。

public Boolean CheckIPValid(String strIP)
{
char chrFullStop = '.';
string[] arrOctets = strIP.Split(chrFullStop);
if (arrOctets.Length != 4)
{
return false;
}
Int16 MAXVALUE = 255;
foreach (String strOctet in arrOctets)
{
if (strOctet.Length > 3)
{
return false;
}

temp = int.Parse(strOctet);
if (temp > MAXVALUE)
{
return false;
}
}
return true;
}




 

posted on 2019-04-10 15:50  odsxe  阅读(432)  评论(0编辑  收藏  举报