Qt正則表達式限制輸入


中文匹配:

    QRegExp reg("^[\u4e00-\u9fa5]+$");
    QValidator*validator = new QRegExpValidator(reg);
    ui->lineEdit->setValidator(validator);

字母數字匹配:

    QRegExp reg("^[a-zA-Z0-9]+$");
    QValidator*validator = new QRegExpValidator(reg);
    ui->lineEdit->setValidator(validator);

IP、Port、Channel匹配:

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_IP->setValidator(new QRegExpValidator(regExpIP));
ui->lineEdit_NetPort->setValidator(new QRegExpValidator(regExpNetPort));
ui->lineEdit_Channel->setValidator(new QRegExpValidator(regExpChannel));

  


免責聲明!

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



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