使用jquery进行日期验证,防止进入未来的日期。 [英] Date validation using jquery, prevent entering yeterdays date.
本文介绍了使用jquery进行日期验证,防止进入未来的日期。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试验证日期输入字段。
我可以阻止jquery datepicker阻止使用
I am trying to validate a date input field. I can prevent jquery datepicker to prevent from entering old dates using,
$('#delivery_date').datePicker({ minDate: 0 });
但用户仍然可以手动输入日期。如何预防或验证?
But user can still enter date manually. How to prevent or validate this?
推荐答案
// 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());
}
})
这篇关于使用jquery进行日期验证,防止进入未来的日期。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文