Check it out . I tried this without expecting it to work.
In fact, you can use RegExp to check for DateTime in MVC . This is my setup:
RegExp attribute property:
[RegularExpression (@ "(^ $) | (^ \ d {2} / \ d {2} / \ d {4}) | (^ ((\ d {1}) | (\ d {2})) / ((\ d {1}) | (\ d {2})) / (\ d {4}) \ S ((\ d {1}) | (\ d {2})) [:] {1 } ((\ d {1}) | (\ d {2})) [:] {1} ((\ d {1}) | (\ d {2})) \ s ((AM) | (PM ))) ", ErrorMessage =" Invalid date ")]
Forced check: Empty line, 1 or 2 digits for the month / date in the format MM / dd / yyyy (e.g. 3/20/2015 or 03/20/2015 or 3/2/2015), C # date (e.g. MM / dd / yyyy hh: mm: ss tt) is what allows ModelState.IsValid to return true for this property as soon as the server converts it to C # DateTime
TextBoxTo view: @ Html.TextBoxFor (x => x.DateOfWeightAndHeightCapture, "{0: MM / dd / yyyy}", new {@ class = "form-control"})
This allows you to have the DateTime property on the model edited using MVC TextBoxFor, which provides client and server side validation.
source share