0

我有一个函数,它需要月份和年份并检查它是否是过去的。除非您选择两位数的月份,例如 11/2013,否则它可以正常工作。它认为这是过去。

我如何获得像 10/2013 这样的日期来验证?

creditDate = function(){
now = new Date();
month = now.getUTCMonth();
year = now.getUTCFullYear();
current = month + "/" + year;
selectedMonth = $('#ctl00_MainContentHolder_Payment1_CreditCardInput1_ExpMonthField')
yourMonth = selectedMonth.val();
selectedYear = $('#ctl00_MainContentHolder_Payment1_CreditCardInput1_ExpYearField')
yourYear = selectedYear.val();
yourDate = yourMonth + "/" + yourYear
if (yourDate < current){
    selectedMonth.css('background-color', 'pink');
    selectedYear.css('background-color', 'pink');
    $('#errorAlertTwo').append('Credit card expiration date is invalid.' + '<br>');
    return false;
        } else {
        return true;
    } 
}
4

1 回答 1

0

只需按年、按月进行

if (yourYear < currentYear || (yourYear == currentYear && yourMonth < currentMonth)) {
    selectedMonth.css('background-color', 'pink');
    selectedYear.css('background-color', 'pink');
    $('#errorAlertTwo').append('Credit card expiration date is invalid.' + '<br>');
    return false;
    }
else {
    return true;
}
于 2013-04-29T20:53:02.203 回答