PDA

View Full Version : QRegExpValidator



TheKedge
28th February 2007, 13:08
ok, I know this is silly,

but I've got a QLineEdit. I want it to take numbers from 0 up to 180.00. A QDoubleValidator isn't exactly the right thing (cos I can still type 12345.6789 and the validator is waiting for a possible 'E-2' say - at least I assume so). So I'm thinking QRegExpValidator.

I know somebody out there can punch out the regExp really quickly - so what is it?

any positive number with up to two decimal places up to 180.00.

sorry to ask but I'll be hours trying to figure it out... I'm starting now anyway
thanks
K

TheKedge
28th February 2007, 13:18
Well,
ok there are better ways than this I suppose

Eg. QRegExp("\\d{0,3}^.\\d{0,2}") to get positive decimals from 0.0 to 999.99

and then a
double value = text->toDouble(&ok)
and asking
if(value >180.0){
value = 180.0;
or
user message - whatever
}

TheKedge
28th February 2007, 14:07
just to labour the point

I think
QRegExp("[0-9]{1,3}\\.?[0-9]{0,2}")
will take numbers from 0 to 999.99
using "\\d" instead of [0-9] will accept the minus sign '-' as input

thanks
K