QML中日期和时间的正则表达式(DD/MM/YYYY hh:mm:ss) [英] Regular Expression for date and time(DD/MM/YYYY hh:mm:ss) in QML

查看:143
本文介绍了QML中日期和时间的正则表达式(DD/MM/YYYY hh:mm:ss)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 QML2 中,我没有找到任何 Calender 控件,我已经实现了一个将日期和时间作为输入的控件,并且我正在使用正则表达式进行验证,它匹配包括闰年和其他验证.

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:

ss/ss/ss ss:ss:ss

以下是代码:

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: /^(((([0s][1-9s]|[1s][0-9s]|[2s][0-8s])[/]([0s][1-9s]|[1s][012s]))|((29|30|31)[/]([0s][13578s]|[1s][02s]))|((29|30)[/]([0s][4,6,9]|11)))[/]([19s[2-9s][0-9s])dd|(^29[/]02[/]([19s]|[2-9s][0-9s])(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-1s]?[0-9s]|2[0-3s]):([0-5s][0-9s]):([0-5s][0-9s])$/}

    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.

推荐答案

你匹配年份的顺序是:

([19s[2-9s][0-9s])dd

看起来格式不正确,因为括号不匹配.

Which looks malformed, as the brackets do not match.

另外,两个数字的存在(使用d)意味着表达式将不匹配空格.

Also, the presence of the two digits (using d) means that the expression will not match white space.

这篇关于QML中日期和时间的正则表达式(DD/MM/YYYY hh:mm:ss)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆