I have a Asp.Net web app and I have the following date defined in my model:
[Required]
[Display(Name = "Birth Date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:MMM-dd-yyyy}", ApplyFormatInEditMode = true)]
[RegularExpression(@"(((0[1-9]|1[0-2])\/(0|1)[0-9]|2[0-9]|3[0-1])\/((19|20)\d\d))$", ErrorMessage = "Invalid date format.")]
public DateTime BirthDate { get; set; }
When the viewis retrieved, the birth date set to the field from the database is: 1/18/1985 12:00:00 am
I change it to: 01/18/1985 and submit the Form.
The controller server-side validation catches it as an error - invalid date format.
What am I doing wrong?
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vinay SinghPosted Mar 31, 2020, 1:28 AM
Rajanikant HawaldarPosted Mar 31, 2020, 12:13 AM
Jignesh KumarPosted Mar 30, 2020, 12:08 PM