开发者

regular expression dates

开发者 https://www.devze.com 2023-02-17 22:12 出处:网络
# Montag 28.03.2011 # Mi, 23.03.11 ^([1-9]|0[1-9]|[12][0-9]|3[01])[-/.]([1-9]|0[1-9]|1[012])[- /.][0-9]{4} or with \\d{2}[.]\\d{2}[.]\\d{4}
# Montag 28.03.2011
# Mi, 23.03.11

^([1-9]|0[1-9]|[12][0-9]|3[01])[-/.]([1-9]|0[1-9]|1[012])[- /.][0-9]{4} or with \d{2}[.]\d{2}[.]\d{4}

works for 28.03.2011 but not for 23开发者_StackOverflow中文版.03.11. can i automatically add 20 before 11 if year is just 11?


^([1-9]|0[1-9]|[12][0-9]|3[01])[-/.]([1-9]|0[1-9]|1[012])[- /.]([0-9]{4}|[0-9]{2})$

How about the above

By the way this is just pattern matching so it will match invalid dates too. eg:30.02.2011


Why not use one of the methods available in the System.DateTime namespace? You could use DateTime.TryParseExact()

0

精彩评论

暂无评论...
验证码 换一张
取 消