Chinaunix首页 | 论坛 | 博客
  • 博客访问: 528718
  • 博文数量: 108
  • 博客积分: 3242
  • 博客等级: 中校
  • 技术积分: 916
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-07 11:46
文章分类
文章存档

2012年(13)

2010年(95)

分类: C/C++

2010-12-20 17:16:20

 

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;
}


阅读(2374) | 评论(1) | 转发(0) |
0

上一篇:QTreeView

下一篇:在QT中显示中文

给主人留下些什么吧!~~

chinaunix网友2010-12-22 14:34:39

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com