我想验证日期输入字段。 我可以防止jQuery的日期选择使用旧进入日期,以防止,使用jquery进行日期验证,防止输入yeterdays日期。
$('#delivery_date').datePicker({ minDate: 0 });
但用户仍然可以手动输入日期。如何防止或验证此?
我想验证日期输入字段。 我可以防止jQuery的日期选择使用旧进入日期,以防止,使用jquery进行日期验证,防止输入yeterdays日期。
$('#delivery_date').datePicker({ minDate: 0 });
但用户仍然可以手动输入日期。如何防止或验证此?
// when the field changes value
$('#delivery_date').on('change',function(){
var today = new Date();
today = new Date(today.getYear(), today.getMonth(), today.getDate());
// compare the value of the field with whatever you want to test against
if($(this).val() > today){
// if the test fails, change the value to default
$(this).datepicker('setDate', new Date());
}
})
$('#delivery_date').on('change', function(){
var today = new Date();
if(new Date($(this).val()) < new Date(today.getYear(), today.getMonth() - 1, today.getDate()) $(this).datepicker('setDate', new Date());
});
你好你能确认的maxDate工作,因为它不是为我工作,($( '#DELIVERY_DATE')日期选择器({开始日期:。'01/01/1970' 年,的maxDate: “+5”});)对日期选择没有任何影响,因为我可以选择任何日期。 –
感谢球员....我会尝试这些。作为一个临时的措施,我使日期输入字段只读....只有输入日期的方法是选择使用datepicker。在日期选择器中,我禁用了过去的日期。 –
请记住,所有客户端代码都可以绕过并且被覆盖。您必须复制验证服务器端以确保数据完整性 - 客户端验证仅供用户使用。 –