Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QRegExp - Question on defining a regular expression
Forum Updated to NodeBB v4.3 + New Features

QRegExp - Question on defining a regular expression

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Klondike6
    wrote on last edited by
    #1

    I am using QRegExp to validate user input. I would like the user to input a number from 0 to 255. (Eventually this will be used to validate input of an IP address like 192.168.0.123)

    At this point, I have a working expression that allows the user to enter 1-3 digits, each in the range 0-9:
    [0-9]{1,1}[0-9]{0,1}[0-9]{0,1}

    This works, but allows the user to enter values from 0 to 999. How best to restrict the input to 0 to 255?

    If the first digit entered is greater than 2, then we can only allow one more digit.
    If the first digit is equal to 2, then if the user enters a total of three digits, the second and third digits cannot exceed 5.

    Any guidance is appreciated.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Have a look to "this thread":http://developer.qt.nokia.com/forums/viewthread/5736

      From this thread the Octet is what you are looking for
      @
      QString Octet = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
      @

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Klondike6
        wrote on last edited by
        #3

        Exactly what I needed, thanks!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved