Search code examples
regexqregexpinput-mask

Validate Degree and Character (Regex)


I need to validate given string from QLineEdit. True Input: 355.12° L

The double number must be between 0-360, and the last character must be L or R. I have used QString mask for degree(°) and this example for 360 but i can't use mask and QDoubleValidator together. Looks like only the way is QRegExp to solve this problem.

My mask string:

">999.99°A"

Solution

  • ((?:[012]?[0-9]{1,2}|3(?:[0-5][0-9]|60))(?:\.[0-9]{0,2})?)°[LR]
    

    Try the above pattern. I'm not sure if qregexp supports (?:) patterns or not though.