Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. RegExpValidator + InputMask for IP TextField
Forum Updated to NodeBB v4.3 + New Features

RegExpValidator + InputMask for IP TextField

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 4 Posters 5.1k Views 4 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.
  • R Offline
    R Offline
    rrr_rrr_rrr
    wrote on 23 Mar 2017, 19:21 last edited by
    #1

    Hello,

    OS: Ubuntu 15.04
    Qt: 5.7

    I am trying to create an IP TextFild with inputMask for view and validator for input limit. My QML code is:
    T.TextField {
    id: textField

        width: 400
        height: 40
        color: "magenta"
        leftPadding: 20
        focus: true
        font {
            pixelSize: 30
        }
    

    // inputMask: "000.000.000.000;_"
    inputMask: "000.000.000.000;0"
    validator: RegExpValidator {
    regExp: /^((?:[0-1]?[0-9]?[0-9]|2?[0-4]?[0-9]|25[0-5]).){3}(?:[0-1]?[0-9]?[0-9]|2?[0-4]?[0-9]|25[0-5])$/
    }
    }

    When I choose '0' filler for inputMask it works as expected but when filler is '_ ' it does not work - it allows to set 347.569.436.300, for example.
    As I understand there should not be any difference between '0' and '_' fillers in the inputMask property.
    Why have I had the difference? Should some properties be set to some specific values?
    Thanks in advance

    R 1 Reply Last reply 24 Mar 2017, 02:26
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 23 Mar 2017, 19:30 last edited by
      #2

      Jesus, it's 2017 and you're writing new code for IPv4...

      R 1 Reply Last reply 24 Mar 2017, 02:14
      1
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 23 Mar 2017, 22:12 last edited by
        #3

        Hi,

        Likely because your regular expression doesn't allow the _ character.

        You should take into consideration @Wieland's remark: we are entering IPV6 age.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • ? A Former User
          23 Mar 2017, 19:30

          Jesus, it's 2017 and you're writing new code for IPv4...

          R Offline
          R Offline
          rrr_rrr_rrr
          wrote on 24 Mar 2017, 02:14 last edited by
          #4

          @Wieland An IP input mask is just an example in this case. What is the difference what kind of data I am trying to enter?

          1 Reply Last reply
          0
          • R rrr_rrr_rrr
            23 Mar 2017, 19:21

            Hello,

            OS: Ubuntu 15.04
            Qt: 5.7

            I am trying to create an IP TextFild with inputMask for view and validator for input limit. My QML code is:
            T.TextField {
            id: textField

                width: 400
                height: 40
                color: "magenta"
                leftPadding: 20
                focus: true
                font {
                    pixelSize: 30
                }
            

            // inputMask: "000.000.000.000;_"
            inputMask: "000.000.000.000;0"
            validator: RegExpValidator {
            regExp: /^((?:[0-1]?[0-9]?[0-9]|2?[0-4]?[0-9]|25[0-5]).){3}(?:[0-1]?[0-9]?[0-9]|2?[0-4]?[0-9]|25[0-5])$/
            }
            }

            When I choose '0' filler for inputMask it works as expected but when filler is '_ ' it does not work - it allows to set 347.569.436.300, for example.
            As I understand there should not be any difference between '0' and '_' fillers in the inputMask property.
            Why have I had the difference? Should some properties be set to some specific values?
            Thanks in advance

            R Offline
            R Offline
            rrr_rrr_rrr
            wrote on 24 Mar 2017, 02:26 last edited by
            #5

            Hello,
            As I understand a filler and other symbols in the input mask are not just "decoration" which helps to understand what kind of data the user should enter. Each symbol in an input mask is full-fledged symbol, looks like user entered.
            So, how can I get a set of symbols which were really entered? In another words how can I separate the input mask and the entered symbols?

            T 1 Reply Last reply 24 Mar 2017, 12:28
            0
            • R rrr_rrr_rrr
              24 Mar 2017, 02:26

              Hello,
              As I understand a filler and other symbols in the input mask are not just "decoration" which helps to understand what kind of data the user should enter. Each symbol in an input mask is full-fledged symbol, looks like user entered.
              So, how can I get a set of symbols which were really entered? In another words how can I separate the input mask and the entered symbols?

              T Offline
              T Offline
              the_
              wrote on 24 Mar 2017, 12:28 last edited by
              #6

              @rrr_rrr_rrr

              the regexp is wrong for IPv4 addresses.
              it correctly matches the numbers from 0 to 255 for each block. but it accepts ANY character as delimiter

              you should use \. instead of . (which means ANY single character)

              @Wieland & @SGaist IPv6 in a private LAN? ;)

              -- No support in PM --

              R 1 Reply Last reply 24 Mar 2017, 19:49
              2
              • T the_
                24 Mar 2017, 12:28

                @rrr_rrr_rrr

                the regexp is wrong for IPv4 addresses.
                it correctly matches the numbers from 0 to 255 for each block. but it accepts ANY character as delimiter

                you should use \. instead of . (which means ANY single character)

                @Wieland & @SGaist IPv6 in a private LAN? ;)

                R Offline
                R Offline
                rrr_rrr_rrr
                wrote on 24 Mar 2017, 19:49 last edited by
                #7

                I am trying to create an number text field with number range [0..255]. My QML code is:

                T.TextField {
                id: textField

                    width: 400
                    height: 40
                    color: "magenta"
                    leftPadding: 20
                    focus: true
                    font {
                        pixelSize: 30
                    }
                    inputMask: "000;0"
                

                // inputMask: "000;_"
                validator: RegExpValidator {
                regExp: /^(?:[0-1]?[0-9]?[0-9]|2?[0-4]?[0-9]|25[0-5])$/
                }
                Rectangle {
                anchors.fill: parent
                color: "transparent"
                border {
                width: 2
                color: "yellow"
                }
                }
                }

                When I choose '0' filler for inputMask it works as expected but when filler is '_ ' it does not work - it allows to set 347, for example.

                My questions are:

                1. Why am I having the different behaviour with '_' and '0' fillers?
                2. How can I get a set of symbols which were really entered? Why is filler from mask a full-fledged symbol, not just a "decorator"?
                1 Reply Last reply
                0

                1/7

                23 Mar 2017, 19:21

                • Login

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