Qt中限制IP输入的正则表达式:
这个例子中,是使用QLineEdit加入正则表达式来实现ip地址的输入功能的,不符合规范的数据将不能输入:
- QRegExp regExpIP("((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])[\\.]){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])");
- QRegExp regExpNetPort("((6553[0-5])|[655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[0-9])");
- QRegExp regExpChannel("[0-5]");
- ui->lineEdit_locIP->setValidator(new QRegExpValidator(regExpIP,this));
- ui->lineEdit_subNetMask->setValidator(new QRegExpValidator(regExpIP,this));
- ui->lineEdit_GatewayIP->setValidator(new QRegExpValidator(regExpIP,this));
- ui->lineEdit_serIP->setValidator(new QRegExpValidator(regExpIP,this));
- ui->lineEdit_serPort->setValidator(new QRegExpValidator(regExpNetPort,this));
- ui->lineEdit_rfChannel->setValidator(new QRegExpValidator(regExpChannel,this)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步