Using Regular expression how to check the Empty DateTime Value in my MVC2 validation
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; }
精彩评论