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