繁体   English   中英

如何验证/检查插入日期到当前日期

[英]how to validate/check the inserted date to current date

我是PHP新手。 我有一张存储日期的表。

id     nic     date
1      765     2012-04-20
2      654     2012-03-19
3      777     2011-01-08

我正在使用jQuery日历插入日期。 我不知道如何将此日期验证为当前日期,以便用户无法输入小于当前日期的日期。

我只想插入等于或大于当前日期的日期。

在我的数据选择器初始化代码中

var A_TCALCONF = {
    'cssprefix'  : 'tcal',
    'months'     : ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
    'weekdays'   : ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
    'longwdays'  : ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
    'yearscroll' : true, // show year scroller
    'weekstart'  : 0, // first day of week: 0-Su or 1-Mo
    'prevyear'   : 'Previous Year',
    'nextyear'   : 'Next Year',
    'prevmonth'  : 'Previous Month',
    'nextmonth'  : 'Next Month',
    'format'     : 'Y-m-d' //'d/m/Y' // 'd-m-Y', Y-m-d', 'l, F jS Y'
};

var A_TCALTOKENS = [
     // A full numeric representation of a year, 4 digits
    {'t': 'Y', 'r': '19\\d{2}|20\\d{2}', 'p': function (d_date, n_value) { d_date.setFullYear(Number(n_value)); return d_date; }, 'g': function (d_date) { var n_year = d_date.getFullYear(); return n_year; }},
     // Numeric representation of a month, with leading zeros
    {'t': 'm', 'r': '0?[1-9]|1[0-2]', 'p': function (d_date, n_value) { d_date.setMonth(Number(n_value) - 1); return d_date; }, 'g': function (d_date) { var n_month = d_date.getMonth() + 1; return (n_month < 10 ? '0' : '') + n_month }},
     // A full textual representation of a month, such as January or March
    {'t': 'F', 'r': A_TCALCONF.months.join('|'), 'p': function (d_date, s_value) { for (var m = 0; m < 12; m++) if (A_TCALCONF.months[m] == s_value) { d_date.setMonth(m); return d_date; }}, 'g': function (d_date) { return A_TCALCONF.months[d_date.getMonth()]; }},
     // Day of the month, 2 digits with leading zeros
    {'t': 'd', 'r': '0?[1-9]|[12][0-9]|3[01]', 'p': function (d_date, n_value) { d_date.setDate(Number(n_value)); if (d_date.getDate() != n_value) d_date.setDate(0); return d_date }, 'g': function (d_date) { var n_date = d_date.getDate(); return (n_date < 10 ? '0' : '') + n_date; }},
    // Day of the month without leading zeros
    {'t': 'j', 'r': '0?[1-9]|[12][0-9]|3[01]', 'p': function (d_date, n_value) { d_date.setDate(Number(n_value)); if (d_date.getDate() != n_value) d_date.setDate(0); return d_date }, 'g': function (d_date) { var n_date = d_date.getDate(); return n_date; }},
     // A full textual representation of the day of the week
    {'t': 'l', 'r': A_TCALCONF.longwdays.join('|'), 'p': function (d_date, s_value) { return d_date }, 'g': function (d_date) { return A_TCALCONF.longwdays[d_date.getDay()]; }},
    // English ordinal suffix for the day of the month, 2 characters
    {'t': 'S', 'r': 'st|nd|rd|th', 'p': function (d_date, s_value) { return d_date }, 'g': function (d_date) { n_date = d_date.getDate(); if (n_date % 10 == 1 && n_date != 11) return 'st'; if (n_date % 10 == 2 && n_date != 12) return 'nd'; if (n_date % 10 == 3 && n_date != 13) return 'rd'; return 'th'; }}

];

您可以禁用jquery日历过去的日期,以便在插入时无需检查。

您可以在日期选择器初始化时执行此操作。

var dates = $("#from").datepicker({
defaultDate: "+1w",   
minDate: new Date()
}
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM