Jquery格式YY / MM / DD的正则表达式 [英] Jquery Regular expression for Format YY/MM/DD

查看:311
本文介绍了Jquery格式YY / MM / DD的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨团队,



我想在YYYY / MM / DD中使用日期格式的正则表达式。

我正在尝试这个:

/ ^(19 | 20)\\\ [ - /。](0 [1-1] | 1 [010])[/ /](0 [1-] 9] | [12] [0-9] | 3 [01])$ ​​/;



它不起作用。

它的节目我错了:

正则表达式中的语法错误。



请帮助....

问候

Harshal Raut

解决方案

/;



无效。

它告诉我一个错误:

正则表达式中的语法错误。



请帮助....

问候

Harshal Raut


如果你想要像2013/12/25这样的日期格式的正则表达式,试试这个

(\d){4}(\ /)([0] [1-9] | [1] [012])(\ /)([0] [ 1-9] | [12] [1-9] | [3] [01])



要在代码中使用它,请说java,javascript或c#,你将不得不用'\'来逃避'\'。

你的实际正则表达式工作正常,如果我把它送到Expresso它甚至可以工作 - 问题是字符串分隔符。你用'/'分隔了字符串,但你的字符串也包含'/'字符,它们将作为字符串的结尾....如果你使用不同的字符串分隔符(例如双引号),它应该可以正常工作。

Hi team,

I want to use regular expression for Date Format in YYYY/MM/DD.
I am trying this:
/^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$/;

It not work.
its show me an error:
Syntax error in regular expression.

Please kindly help....
Regards
Harshal Raut

解决方案

/;

It not work.
its show me an error:
Syntax error in regular expression.

Please kindly help....
Regards
Harshal Raut


If you want regex for date format like 2013/12/25, try this

(\d){4}(\/)([0][1-9]|[1][012])(\/)([0][1-9]|[12][1-9]|[3][01])


To use this in your code say java, javascript, or c#, you will have to escape the '\' with '\'.


Your actual Regex works fine, if I feed it into Expresso it even works - the problem is the string delimiters. You have delimited the string with '/' but your string also contains '/' characters, which will act as the end of the string.... If you use a different string delimiter (double quotes for example) it should work fine.


这篇关于Jquery格式YY / MM / DD的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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