QRegExp for strings with numbers
Hi!
I need a regexp which accepts a string (maximum 30 characters/Slots) with:
- letters from A to Z (not à or Ñ or Ë...)
- numbers
- spaces
- signs: . , -
No matter the order so valid examples are :
- Hello how are you
- Hi. My -name- is ... mm
I was trying with that but it just accepts letters and numbers:
Code:
myLineEdit->setValidator(validator7);
Thank you so much
Re: QRegExp for strings with numbers
It only accepts letters and numbers because that's what your regexp contains. You have to put the remaining allowed characters in the selector as well.
Re: QRegExp for strings with numbers
Hi wysota,
Yes I knwo but I don't know how to put dot, coma, spaces and - too. Tried also with that but it accepts too !"··%$&%((/=)**^¨`+
Re: QRegExp for strings with numbers
That's because an unescaped dot in a regular expression means "match anything".
Cheers,
_
Re: QRegExp for strings with numbers
Read about "special characters in regexp". It should looks like :
Code:
QRegExp rx7
("[A-Z\\.\\- 0-9]{0,30}");
Double backslash derived from the principles of code C / C ++.
Re: QRegExp for strings with numbers
wow didn't know that about dot anda_skoa
Thanks Lesiok for the clear example :) You all helped me so much in a moment. :)