c++ - Qt 验证器正则表达式

标签 c++ regex qt

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

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]$

关于c++ - Qt 验证器正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18492640/

相关文章:

c++ - C++11 中的 decltype(auto) - 推导返回类型

c++ - 如何读取注册表的键值并使用 MessageBox() 将其打印到屏幕上

regex - sed 搜索并替换 html 标签

c# - 为什么 .NET 中的 $ 多行正则表达式不匹配 CRLF?

c++ - 在 C++ 中将字符串乘以 int

c++ - 解决模板类之间的循环依赖

c# - 有条件地为逗号分隔字符串中的标记添加前缀

python - QCalendar 样式。禁用项目的属性

c++ - 如何将整数变量转换为 QTime 对象

c++ - QML 应用程序与 QML/C++ 应用程序