普通的前pression为DDMMYYYY日期,包括检验闰年 [英] Regular expression for ddmmyyyy date including validation for leap year

查看:130
本文介绍了普通的前pression为DDMMYYYY日期,包括检验闰年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何检查使用常规的前pression在DDMMYYYY格式(包括闰年验证)的日期?什么是正规的前pression ...?


解决方案

老兄,你问我已经工作了几个星期的问题。我邀请这些评论给打破这个日期。现在注意,这适用于该年的 1000-9999 Proleptic阳历 并假设我们将不会改变跨越式几年的工作,直到9999年;)

<$p$p><$c$c>^(?:(?:(?:0[1-9]|1\\d|2[0-8])(?:0[1-9]|1[0-2])|(?:29|30)(?:0[13-9]|1[0-2])|31(?:0[13578]|1[02]))[1-9]\\d{3}|2902(?:[1-9]\\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00))$

Debuggex演示

How can we check the date in ddmmyyyy format (including leap year validation) using regular expression? What would be the regular expression...?

解决方案

Dude, you asked the question I've been working on for a couple of weeks. I invite those commenting to give a date that breaks this. Now note that this works for the years 1000-9999, is Proleptic Gregorian and assumes that we won't change how leap-years work until the year 9999 ;)

^(?:(?:(?:0[1-9]|1\d|2[0-8])(?:0[1-9]|1[0-2])|(?:29|30)(?:0[13-9]|1[0-2])|31(?:0[13578]|1[02]))[1-9]\d{3}|2902(?:[1-9]\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00))$

Debuggex Demo

这篇关于普通的前pression为DDMMYYYY日期,包括检验闰年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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