TextField Validation in QML



  • I am having a TextField which allows the user to enter time and I have used RegValidator to validate. Currently, i need to fill with "0" when user clicks on backspace. Following is the code:

    TextField {
        id:textField
        text:"11:11:11"
        width:200
        height:80
        font.pointSize: 15
        color:"white"
        inputMask: "99:99:99"
        validator: RegExpValidator { regExp: /^([0-1\s]?[0-9\s]|2[0-3\s]):([0-5\s][0-9\s]):([0-5\s][0-9\s])$ / }
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
        inputMethodHints: Qt.ImhDigitsOnly
    }

Log in to reply
 

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