【发布时间】:2021-07-09 19:17:46
【问题描述】:
我想对我的模型类进行日期验证,我希望验证限制 18 岁以下的用户给出错误消息,例如您的年龄不符合要求,日期为日历格式,因此任何像 02/02/9999 这样的不规则年份选择也必须通过使用验证引发错误,任何人都可以通过使用任何类型的正则表达式来帮助我解决这个问题吗?
代码:
public class AdmissionModel
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Std_id { get; set; }
[Required]
[StringLength(50)]
public string std_name { get; set; }
[Required]
[StringLength(50)]
public string std_father { get; set; }
[Required]
[StringLength(50)]
public string std_mother { get; set; }
[Required]
[DataType(DataType.Date)]
public string DOB { get; set; } ---This is the date--
}
【问题讨论】:
-
使用流利的验证API。它有你需要的一切。
标签: c# asp.net asp.net-mvc asp.net-mvc-4 model-view-controller