正则表达式来检查,如果字符串格式和QUOT; YYYY / MM / DD"是一个有效的日期,包括月份界限 [英] Regex that checks if string in format "yyyy/mm/dd" is a valid date, including month bounds

查看:90
本文介绍了正则表达式来检查,如果字符串格式和QUOT; YYYY / MM / DD"是一个有效的日期,包括月份界限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证在C#中的日期格式为YYYY / MM / DD。它甚至有可能(使用正则表达式)来验证,有没有30天月?

I am trying to validate a date in c# in the format "yyyy/mm/dd". Is it even possible (using regex) to validate that there aren't 30 days in February?

推荐答案

这是可能的正则表达式来做到这一点,但是这将是极其复杂的。我很舒服编写正则表达式,但我不会使用该解决方案来验证日期。

It is possible to do this with a regex, but it would be incredibly complex. I am quite comfortable writing regular expressions, but I would not use that solution to validate dates.

这是更易于使用另一种解决方案,用于验证的日期。有适用于所有编程语言日期验证组件。我不是.NET的用户,但与快速搜索我找到的DateTime 类,这似乎做到这一点。

It's much simpler to use another solution for validating dates. There are date-validation components available for every programming language. I'm not a user of .NET, but with a quick search I find the DateTime class, which seems to do this.

请参阅.NET Framework开发人员指南,解析日期和时间字符串

See .NET Framework Developer's Guide, "Parsing Date and Time Strings."

这篇关于正则表达式来检查,如果字符串格式和QUOT; YYYY / MM / DD"是一个有效的日期,包括月份界限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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