The pattern I suggest is deliberately long and redundant to be the most efficient as possible (the goal is to reduce the most possible the regex engine work):
QRegExp exp("^(?:[1-2][0-9]{0,2}(?:\\.[0-9]{1,2})?|3(?:[0-5]?[0-9]?(?:\\.[0-9]{1,2})?|60(?:\\.00?)?)|[4-9][0-9]?(?:\\.[0-9]{1,2})?|0(?:\\.[0-9]{1,2})?)° ?[LR]$");
lineEdit_->setValidator(new QRegExpValidator(exp, this));
This pattern forbids leading zeros for tens and hundreds and makes optional the decimals that limited to two digits (thus, a trailing or a leading dot is not allowed)
An optional space is allowed between °
and L
(or R
)
Now, if you need a pattern that fits exactly the mask 999.99°A
(i.e. leading zeros are correct, there are no optional spaces anywhere, there is always three digits and two decimal digits), you can use this pattern instead of the previous:
^(?:[0-2][0-9]{2}\\.[0-9]{2}|3(?:[0-5][0-9]\\.[0-9]{2}|60\\.00))°[LR]$