my main goal right now is to forbid some chars entering in line edit.I want to forbid (!@#$%^&*()) chars, cause i do use SQL Database and someone can damage my database without filters for this chars.I tried to use setInputMask but in this way i can use only alphabets.I need to use '-' sign too for some names like "Anna-Maria". So finally, setInputMethodHints is not working and i don't know what to do. I just need to forbid some "dangerous" chars. If you can, please provide me some source code. Thank you in advance.
Asked
Active
Viewed 614 times
1 Answers
2
Use QRegExpValidator to allow only a-z A-Z 0-9 and '-' character. If you want to add more character just put \charactor in to the rx(".."); like I did with '-' by adding \-
QRegExp rx("[a-zA-Z0-9\-]*");
ui.lineEdit->setValidator(new QRegExpValidator(rx,ui.textEdit));

trandatnh
- 351
- 8
- 26
-
Thanks a lot man!. Yesterday i wrote my own algorithm for this, but your way is better.Now everything is working fine.Thanks again ;) – Rado G Jul 21 '13 at 12:19