2014-09-29 61 views

回答

5
QRegExp rx("regex"); 
QValidator *validator = new QRegExpValidator(rx, this); 

QLineEdit *edit = new QLineEdit(this); 
edit->setValidator(validator); 

凡正則表達式的字符串:

[a-zA-Z]+ 

對於數字:

[0-9]+ 
+0

@LionKing請出示你的代碼,你應該包括QRegExp和QRegExpValidator寫QRegExp RX(「[0 -9] +「);如果它沒有幫助,那麼顯示你的代碼 – Chernobyl 2014-09-29 12:31:05

+0

@LionKing它應該是QRegExp模式(「[a-zA-Z] +」);編譯器不能轉換你的代碼。 – Chernobyl 2014-09-29 12:35:52

+1

@LionKing數字有'QIntValidator'和'QDoubleValidator'。使用正則表達式進行數字驗證的開銷很大。此外,還可能存在國際化問題。 – 2014-09-29 13:02:32