正则表达式和ISO8601格式的DateTime [英] Regex and ISO8601 formatted DateTime
本文介绍了正则表达式和ISO8601格式的DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个DateTime字符串ISO8601格式化
I have a DateTime string ISO8601 formated
2012-10-06T04:13:00+00:00
和以下不符合此字符串的正则表达式
and the following Regex which does not match this string
#(\d{4})-(\d{2})-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})\+(\d{2})\:(\d{2})#
我不知道为什么它不匹配。
I can't figure out why it does not match.
我逃脱了元字符对我来说似乎是可以的。
I escaped metacharacters, for me it seems to be OK.
编辑:
正确的方式: http://jsfiddle.net/5n5vk/3/
推荐答案
在js中指定正则表达式时,不要引用正则表达式。正向斜杠就足够了。
Don't quote the regex when specifying a regex in js. Forward slash is enough.
alert($('#datepicker').val());
if($('#datepicker').val().match(
/(\d{4})-(\d{2})-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})[+-](\d{2})\:(\d{2})/
)) {
alert('ok');
} else {
alert('not ok');
}
这篇关于正则表达式和ISO8601格式的DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文