如下的代码是关于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;
}