bool MainWindow::IsIPaddress(QString ip)
{
QRegExp rx2("(\\d+)(\\.)(\\d+)(\\.)(\\d+)(\\.)(\\d+)");
int pos = rx2.indexIn(ip);
if(pos>-1)
{
for(int i=0;i<4;i++)
{
if( rx2.cap(i*2+1).toInt()>=255 )
{
QMessageBox::information(this, tr("错误"), tr("IP地址错误"));
return false;
}
}
if(rx2.cap(7).toInt()==0)
{
QMessageBox::information(this, tr("错误"), tr("IP地址错误"));
return false;
}
if(rx2.cap(7).toInt()==0)
{
QMessageBox::information(this, tr("错误"), tr("IP地址错误"));
return false;
}
}
else
{
QMessageBox::information(this, tr("错误"), tr("IP地址错误"));
return false;
}
return true;
}
|