我正在尝试验证对 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/