正则表达式以验证UTC日期时间格式 [英] regex to verify UTC date time format
本文介绍了正则表达式以验证UTC日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要为此验证日期时间格式,例如"2014-08-29T06:44:03Z".
I want to validate the date- time format which is like '2014-08-29T06:44:03Z' for this i am looking for a reg ex.
尝试了几种组合,但这些组合对我不起作用.
Tried few combinations but those did not work for me.
推荐答案
尝试此正则表达式
\b[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z\b
有:
\ b
-单词边界,以检查例如'92014-08-29T06:44:03Z'无效
\b
- word boundary, to check what for example '92014-08-29T06:44:03Z' is invalid
[0-9] {n}
-匹配n位数字的数字
[0-9]{n}
- match number with n digits
如果字符串必须仅包含日期时间且不包含其他字符,则使用:
If a string must contain only date-time and no other chars, then use:
^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$
这篇关于正则表达式以验证UTC日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文