2017-02-27 232 views
0

我需要检查QLineEdit中的输入文本是否采用这种格式aaa @ b其中“aaa”可以是BE,WE,TZ,WB,CON,ZWL,SCL,KC1和 “b” 可为b或G ...检查lineEdit输入是否有正确的格式Qt 5 C++

但在输入文本我可以把 “AAA @ b,AAA @ b,AAA @ b” 则必须逗号之后>> @ b < < <

坦克所有的阅读和帮助:)

+0

你尝试过这么远吗? – Steeve

+0

我可以使用逗号来修剪字符串,并在每个修剪过的字符串之前检查@和之后的子字符串,但我希望有一个更简单的回答这个 – Pecurka

+0

我会说,这是一个非常好的解决方案,如果ot工程..我不别以为任何人都会在这里为你写代码。 – Steeve

回答

1

用正则表达式,你可以检查这一点。
例如:

QRegExp regex("^((BE|WE|TZ|CON|ZWL|SCL|KC1)@(B|G)(,|$))+"); 
QLineEdit le; 
le.setText("[email protected]"); 
le.text().contains(regex); // return true 
le.setText("[email protected]@G,[email protected]"); 
le.text().contains(regex); // return false 
le.setText("[email protected],[email protected],[email protected]"); 
le.text().contains(regex); // return true 

问候

+0

谢谢你救了我的一天。问候 – Pecurka