判断合法IP的QT正则表达式

//d+)(//.)(//d+)(//.)(//d+)(//.)(//d判断合法IP的QT正则表达式:bool IsIPaddress(QString ip){ QRegExprx2(“( +)”); 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地址错误”)); returnfalse; }
}
else
{ QMessageBox::information(this, tr(“错误”), tr(“IP地址错误”)); return false; } returntrue;} 判断IP地址更简单的方式是: QRegExprx2(“^([1]?/d/d?|2[0-4]/d|25[0-5])/.([1]?/d/d?|2[0-4]/d|25[0-5])/.([1]?/d/d?|2[0-4]/d|25[0-5])/.([1]?/d/d?|2[0-4]/d|25[0-5])$”) if(!rx2.exactMatch(ip) ) { QMessageBox::information(this, tr(“错误”), tr(“ip地址错误”)); returnfalse; } returntrue; 判断文件名是否含有字母、数字、下划线之外的字符:bool IsRightFilename(QString filename){ QRegExprx(“[A-Za-z_0-9]+”); if(!rx.exactMatch( filename) ) { QMessageBox::information(this, tr(“错误”), tr(“文件名含有其他字符或中文字符”)); returnfalse; } returntrue;}