Qt中限制IP输入的正则表达式:

这个例子中,是使用QLineEdit加入正则表达式来实现ip地址的输入功能的,不符合规范的数据将不能输入:

 

[cpp]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. 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])");  
  2. 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])");  
  3. QRegExp regExpChannel("[0-5]");  
  4.   
  5. ui->lineEdit_locIP->setValidator(new QRegExpValidator(regExpIP,this));  
  6. ui->lineEdit_subNetMask->setValidator(new QRegExpValidator(regExpIP,this));  
  7. ui->lineEdit_GatewayIP->setValidator(new QRegExpValidator(regExpIP,this));  
  8. ui->lineEdit_serIP->setValidator(new QRegExpValidator(regExpIP,this));  
  9. ui->lineEdit_serPort->setValidator(new QRegExpValidator(regExpNetPort,this));  
  10. ui->lineEdit_rfChannel->setValidator(new QRegExpValidator(regExpChannel,this)

转载于:https://www.cnblogs.com/weizhixiang/p/6295591.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值