为datepicker添加自定义验证

时间:2017-04-11 10:23:56

标签: jquery jquery-validate bootstrap-datepicker

如何将日期范围选择器输入控件的自定义验证("daterangerequired")添加到方法$.validator.addMethod()

<div class="input-daterange input-group" autoclose="True" data-calendarWeeks="True" clearBtn="True" defaultSecoundDateStartFrom="10"  endDate="4/11/2019 3:30:40 PM" format="mm/dd/yyyy" orientation="auto" startDate="4/11/2015 3:30:40 PM" todayBtn="False" todayHighlight="True" data-val="true" id="Experience2" name="Experience2" placeholder="Select First Date"   type="text" **data-val-daterangerequired="The Experience2 field is required."**>
  <input class="form-control input-sm from_date" name="Experience2" placeholder="Select First Date" aria-invalid="false">
  <span class="input-group-addon">to</span>
  <input class="form-control input-sm to_date" name="Experience2" placeholder="Select Secound Date" aria-invalid="false">
</div>

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

 $("#id").datepicker({
  onClose: function() {
    /* Validate a specific element: */
    $("form").validate().element("#birthdate");
   }
 });