PDA

View Full Version : QRegExp for validating a float entered ina lineEdit



gt.beta2
28th January 2009, 11:35
Hi,
I want to read a number in the rangue [0; 20] with one "decimal" precision.
Examples:
0
1.5
12.4
14
20

I'm using ...

...
QRegExp regExp("[0-9]{1,1}|1[0-9]{1,1}|20");
lineEdit_t1->setValidator(new QRegExpValidator(regExp, this));
...

This validates integer only but is there a shorter way?
What if i want to extend it for the numbers in the example above?

I supose i could use input masks or something but i am trying the regular expressions.

Thanks

Lesiok
28th January 2009, 12:24
Why not to use QDoubleValidator ?

gt.beta2
28th January 2009, 12:48
Because i didn't knew that one yet ;)
Thanks