I need to limit the maximum date by today date, so I use the next code:
<div class="datepicker"> @Html.TextBoxFor(m => m.Birthdate, "{0:dd.MM.yyyy}", new { @class = "form-control", @style="max-width: 240px;" }) </div> <script type="text/javascript"> $(function () { $('.datepicker input').datepicker({ language: "ru", autoclose: true, format: "dd.mm.yyyy", todayHighlight: true, maxDate: new Date() }); }); </script> Due to some problems between different browsers I use a custom datevalidator also:
jQuery.validator.methods.date = function (value, element) { var pattern = new RegExp('^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$'); return this.optional(element) || pattern.test(value); } As I wrote in the title a restriction by min and max dates doesn't work (I tried to set a min date too). I don't sure but maybe it is due to a cutom validation code. But how do I need to change it then?
P.S. Im sorry if my question is too easy but I don't know much JS.