【发布时间】:2013-09-05 10:35:39
【问题描述】:
我想正确验证日期。如果我输入日期为 21-2-198 而不是 21-2-1988 .日期在 Mvc3 中没有正确验证。我为此使用了正则表达式,但没有用。还有其他方法可以验证日期,包括 MVC 模型中的年份。以下是我在模型中编写的代码
[Required(ErrorMessage = "Activation date is required")]
[Display(Name = "Activation date")]
[RegularExpression(@"/^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d+$/", ErrorMessage = "Enter proper date")]
public DateTime? ActivationDate { get; set; }
【问题讨论】:
-
我相信您的要求可以通过为 DateTime 创建新的验证属性来实现,如下面的 SO 链接中指定的那样。 Date Validation
标签: asp.net-mvc-3 asp.net-mvc-4