开发者

Using Regular expression how to check the Empty DateTime Value in my MVC2 validation

开发者 https://www.devze.com 2023-02-15 08:51 出处:网络
How to validate Datetime property in my MVC2 Validation. I have telerik datetime picker to validate <%= Html.Telerik().DatePicker().Name(\"EffectiveDate\")%>

How to validate Datetime property in my MVC2 Validation.

I have telerik datetime picker to validate

<%= Html.Telerik().DatePicker().Name("EffectiveDate")%>

 [Required(ErrorMessage = "EffectiveDate 开发者_开发百科Must not be empty!")]
            public DateTime EffectiveDate { get; set; }
        }

if I use this code I am not able to validation the EffevtiveDate. Because I am just suspecting that effective date showing as "" instead of null.

how to check "" value using regular expressiong here?

thanks


Try making your model property a nullable DateTime:

[Required(ErrorMessage = "EffectiveDate Must not be empty!")]
public DateTime? EffectiveDate { get; set; }

Then the [Required] attribute should be enough to validate against an empty string.


You could try:

[Required(AllowEmptyStrings = false)]
public DateTime EffectiveDate { get; set; }
0

精彩评论

暂无评论...
验证码 换一张
取 消