正则表达式的具体日期格式 [英] Regex Specific Date Format

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

问题描述

我在想,如果有人能指出我的正则表达式code,它验证此:#### / ## / ##

I was wondering if somebody could point me to a regex code that validates for this: ####/##/##

例如: 1990年5月25日

第二号 0 只能是 0 1 和数 2 ,只为 0 1 2 3 。除此之外,在这个集中的所有其他号码都可以使用(0-9)。

The second number 0 can only be 0 or 1 and the number 2 and only be 0, 1, 2, or 3. Other than that all other numbers in this set are allowed (0-9).

在code应验证,只有9或10个字符共包括斜杠。

The code should validate that there is only 9 or 10 characters in total including the slashes.

推荐答案

如果你只是想验证这一格式,可以使用正则表达式像...

If you only want to validate this format, you can use a regex like...

^\d{1,4}\/[01]?\d\/[0-3]\d$

我测试了一下一些日期这里

这将匹配:

1990/01/01
2012/13/34
2013/1/39
9999/0/00

但拒绝:

23121/32/44
12/05/013
013/000/00

如果您要拒绝无效的日期,以及如 2013年2月29日,你可以检查出的此线程

If you want to reject invalid dates as well such as 2013/02/29, you can check out this thread.

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

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