Regular Expression for date and time(DD/MM/YYYY hh:mm:ss) in QML
Unsolved
QML and Qt Quick
-
In QML2 I didn't find any
Calender
control and I have implemented a control which takes date and time as input and I am using the regular expression for the validation which matches dates including leap year and other validations.The main problem is space/backspace should also be considered as a valid for example:
\s\s/\s\s/\s\s \s\s:\s\s:\s\s
Following is the code :
TextField{ id:textEditDate width:parent.width * 0.50 height:parent.height text : "01/01/2017 00:00:00" inputMask: "99/99/9999 99:99:99" validator: RegExpValidator { regExp: /^(((([0\s][1-9\s]|[1\s][0-9\s]|[2\s][0-8\s])[\/]([0\s][1-9\s]|[1\s][012\s]))|((29|30|31)[\/]([0\s][13578\s]|[1\s][02\s]))|((29|30)[\/]([0\s][4,6,9]|11)))[\/]([19\s[2-9\s][0-9\s])\d\d|(^29[\/]02[\/]([19\s]|[2-9\s][0-9\s])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)))\s([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 inputMethodHints: Qt.ImhDigitsOnly }
Now, everything works well except for the year and I am not able to match backspace/space for the year and user is not able to clear the year.
Can you please suggest how to achieve this ? or is there any other method to do this.
-
For your Calendar control:
- https://stackoverflow.com/questions/21153199/is-there-any-datepicker-control-for-qt-5
- http://doc.qt.io/qt-5/qml-qtquick-controls-calendar.html
?
But I don't imagine there will be a date+time control. I had to implement that myself in previous (non-Qt) projects.