Qt验证器正则表达式

Qt Validator Regular expression

本文关键字:正则表达式 验证 Qt      更新时间:2023-10-16

我正在尝试验证QLineEdit中的条目,但我的语法有错误,因为当我运行程序时,它不允许我在编辑框中输入任何内容。条目需要是3个大写字母字符,后面跟着1,2或3,然后是另外两个数字,最后是一个字母或数字。

QRegExp StudentForm::modCodeFormat("(\s{3}\d[123]\d{2}\w{1})");
(\s{3}\d[123]\d{2}\w{1})
   ^      ^       ^     ^
  This mat|ches wh|ite s|pace characters, not uppercase alphabetics
          |       |     |
        This match|es a |number then either a 1, 2 or a 3
                  |     |
                This mat|ches two numbers
                        |
                   This matches a single word characters, that is either a single number, uppercase, lowercase or an underscore _ character

相反,您应该使用:

^[A-Z]{3}[123][0-9]{2}[a-zA-Z0-9]$