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)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM