中文匹配:

    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));

  

相关文章:

  • 2022-12-23
  • 2022-02-23
  • 2022-02-22
  • 2021-05-25
  • 2021-12-07
  • 2022-12-23
猜你喜欢
  • 2021-09-02
  • 2021-07-14
  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案