Customize the Error Message MVC for an invalid DateTime in ASP.NET MVC4

后端 未结 5 1296
不知归路
不知归路 2020-12-23 15:20

I am having trouble specifying the error message for the validation of a DateTime input value using data annotations in my model. I would really like to use the proper DateT

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-23 15:33

    Try with a regular expression annotation like

    [Required]
    [RegularExpression("\d{4}-\d{2}-\d{2}(?:\s\d{1,2}:\d{2}:\d{2})?")]
    public string Date { get; set; }
    

    or check this

提交回复
热议问题