textBox里仅限输入IP格式 转

bool blnTest = false;
bool _Result = true;

Regex regex = new Regex("^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$");
blnTest = regex.IsMatch(textEdit1.Text);
if (blnTest == true)
{
string[] strTemp = this.textEdit1.Text.Split(new char[] { '.' }); // textBox1.Text.Split(new char[] { '.' });
for (int i = 0; i < strTemp.Length; i++)
{
if (Convert.ToInt32(strTemp[i]) > 255)
{ //大于255则提示,不符合IP格式
MessageBox.Show("不符合IP格式");
_Result = false;
}
}
}
else
{
//输入非数字则提示,不符合IP格式
MessageBox.Show("不符合IP格式");
_Result = false;
}
原文地址:https://www.cnblogs.com/liye/p/1568539.html