RegExpValidator + InputMask for IP TextField



  • 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


  • Moderators

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


  • Lifetime Qt Champion

    Hi,

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

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



  • @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?



  • 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?



  • @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? ;)



  • 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"?

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.