只需正则表达式日期验证

Zet*_*Zet 2 c# regex asp.net-mvc data-annotations

我正在尝试为我的mvc应用程序创建简单的正则表达式验证。我试过了:

[Required]
[RegularExpression("(\\d\\d\\/\\d\\d\\/\\d\\d\\d\\d)")]
Run Code Online (Sandbox Code Playgroud)

而且它不起作用。我想强制客户以2015年1月1日的格式输入日期

teo*_*kot 5

为什么在这种情况下需要正则表达式?使用DisplayFormatDataType

[Required]
[DataType(DataType.DateTime)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
Run Code Online (Sandbox Code Playgroud)

我的意思是用正则表达式验证日期是错误的。没有简单的方法可以验证日期31/02/201531/04/2015无效日期。