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. inputMask and Validator not working together
Qt 6.11 is out! See what's new in the release blog

inputMask and Validator not working together

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 2.0k 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.
  • michaelLM Offline
    michaelLM Offline
    michaelL
    wrote on last edited by
    #1

    I have a TextField and the user should type in his birthda .
    So i did a validator which works great but once i have an inputMask the validator does not work anymore:

    TextField
     {
                        id: birthField
                        validator: RegExpValidator { regExp: /^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$/ }
                        inputMask: "00-00-0000"
    }
    

    Any idea?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by
      #2

      Hi @michaelL

      I think that the problem is that you were not handling the blank ,

      Actually when you start the program , because of the inputmask birthField.text will be equal to - -

      So your regexp need to handle blank,

      I've just changed your regular expression(with adding blank),this code should work for you

      TextField
          {
              id: birthField
              inputMask: "00-00-0000"
      
              validator:
                  RegExpValidator
              {
                  regExp: /^( [0 ][ 1-9]|[12 ][ 0-9]|[3 ][ 01])[- /.]([0 ][ 1-9]|[1 ][ 012])[- /.]([1 ][ 9]|[2][0-1 ])[\d ][\d ]$/
              }
          }
      

      I hope this can help you ,

      Best regards !

      1 Reply Last reply
      0
      • michaelLM Offline
        michaelLM Offline
        michaelL
        wrote on last edited by
        #3

        @mostefa i tryied but it doenst work. Same error.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Praveen_2017
          wrote on last edited by Praveen_2017
          #4

          @michaelL just set some text to it and it works properly:

          TextField
          {
                id: birthField
                text : "25/09/2017" //Add this
                validator: RegExpValidator { regExp: /^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$/ }
                inputMask: "00/00/0000"
          }
          
          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