I've have client side validation enabled with jquery.validate.js
and jquery.unobtrusive.ajax.js
both referenced on my page. I'm using @Html.TextBoxFor()
to create the inputs in a form.
Client side validation is working correctly except for the dates.
If I try to enter a letter, I get a client side error, which is great.
If I enter a blatantly invalid date like 02/77/2018
, I get a client side error just as expected/desired, like any other type that doesn't pass validation.
However if I enter just an integer in for the date (e.g. 111
), it passes validation. Does anyone know why?
Luckily it doesn't pass my server side validation in the controller, but all my other validation is done client side and i'd like to keep things consistent. I could write some custom code to validate the format of the date, but it seems like there has to be an easier way to make sure the input is in MM/dd/yyyy
or MM-dd-yyyy
format.
To reproduce the issue, refer this DotNetFiddle
- Enter
A
in the textbox and tab out - a error message is shown - Enter
111
in the textbox and tab out - the error message disappears - Enter
11112018
in the textbox and tab out - the error message appears again - Enter
111
again and the error message disappears - Click save - the form is submitted and the server side error message is displayed