liye

liye

博客园 首页 新随笔 联系 订阅 管理
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;
}
posted on 2009-09-17 15:23    阅读(1329)  评论(0编辑  收藏  举报