Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. TextField Validation in QML
Qt 6.12 LTS is out! See what's new in the release blog

TextField Validation in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
textfieldqtquick2qtquickcontrols
1 Posts 1 Posters 1.7k Views
  • 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.
  • P Offline
    P Offline
    pra7
    wrote on last edited by
    #1

    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
    }
    
    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
    • Unsolved