inputMask and Validator not working together



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



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



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



  • @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"
    }
    

Log in to reply
 

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