c# - asp.net mvc 代码中的日期验证优先方法
问题描述
我想对我的模型类进行日期验证,我希望验证限制年龄在 18 岁以下的用户给出错误消息,例如您的年龄不符合要求,日期为日历格式,因此任何不规则的选择像 9999 年 2 月 2 日这样的年份也必须通过使用验证来引发错误,任何人都可以通过使用任何类型的正则表达式来帮助我解决这个问题吗?
代码:
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--
}
解决方案
你可以像这样验证你的日期
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
推荐阅读
- github - nulInCommit: NUL byte in the commit object body
- gcc - 制作依赖关系:使用 gcc 跳过供应商和包头?
- php - 获取帖子作者图片 - Wordpress
- java - 如果不是以管理员身份运行,cmd 无法识别 Java 命令
- summary - BlueSKy 摘要数值统计分析
- javascript - 使用矩js计算数组中所有对象的所有持续时间的总和
- android - 如何在 ScrollView 上显示滚动条?
- bash - 链码参数错误:JSON 输入意外结束
- c# - 我如何处理 C# 中的 Ping 异常
- github - GraphQL | 我们可以使用指令在 GitHub GraphQL API 中通过编程语言实现搜索吗?