//添加引用
using System.Text.RegularExpressions;
//把.和localhost加工一下
string strDataAddess = "";
if ((this.textBox1.Text.ToString().TrimEnd() == ".")
|| (this.textBox1.Text.ToString().TrimEnd() == "localhost")
|| (this.textBox1.Text.ToString().TrimEnd() == "LOCALHOST")
){
strDataAddess = "127.0.0.1";
}
else
{
strDataAddess = this.textBox1.Text.ToString().TrimEnd();
}
//判断
rx = new Regex(@"((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))");
if (rx.IsMatch(strDataAddess))
{
MessageBox.Show("Is IP address");
}
else
{
MessageBox.Show(this.textBox1.Text.ToString().TrimEnd() + "非法服务器地址\n", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
IP判断代码来源于https://blog.csdn.net/taoerit/article/details/60954263