title: Override validator function for dates (ASP MVC 5)
body: <p>I need to override the validator function for a date field defined as:</p>
  
  <pre><code>@*Creation*@
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.Creation, new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.TextBoxFor(model =&gt; model.Creation, "{0:dd/MM/yyyy}", new { @class = "form-control" })
              @Html.ValidationMessageFor(m =&gt; m.Creation)
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Accordingly to <a href="https://stackoverflow.com/questions/42010704/asp-mvc-5-date-format-validation-issue">this thread</a>, this should be a simple solution to fix my date format issue, but when I try to do the suggested approach, no validation happens at all.</p>
  
  <p>Due to my lack of experience in ASP MVC and jquery, I might be missing something simple. I added this override on the same view (cshtml) of the form, under the Scripts Section:</p>
  
  <pre><code>@section Scripts {
  @Scripts.Render("~/bundles/jqueryval")
  &lt;script type="text/javascript"&gt;
      jQuery(function ($) {
          $.validator.addMethod('date',
          function (value, element) {
              $.culture = Globalize.culture("pt-BR");
              var date = Globalize.parseDate(value, "dd/MM/yyyy", "pt-BR");
              return this.optional(element) ||
                !/Invalid|NaN/.test(new Date(date).toString());
          });
      });
  &lt;/script&gt;
  });
  </code></pre>
  
  <p>No validation happens when the script is there. If I remove the script, the validation does not respect the date format.</p>
  
  <p>How can I fix that?</p>