0

<span>タグを入力するクレジットカードフィールドがあります。

<span>****-****-****-1111 (Expires 12/2012)</span>

日付を抽出して、過去のものかどうかを確認する必要があります。

現時点では、以下のjQueryがありますが、日付だけを抽出するためにsplit()の時点で立ち往生しています。

var $selectedDate = $('.prev-card .chzn-container .chzn-single span').text().split();
var $now = new Date();
if ($selectedDate < $now) {
    alert('past')
}
else{
    alert('future')
}

私はそれがすべてをカバーしていると思いますが、より多くの情報を気軽に尋ねてください

4

3 に答える 3

2

これを試して:

var selectedDate = $("...").text().match(/Expires (\d+)\/(\d+)/),
    expires = new Date(selectedDate[2],selectedDate[1]-1,1,0,0,0),
    now = new Date();
if( expires.getTime() < now.getTime()) alert("past");
else alert("future");
于 2012-07-26T15:32:49.103 に答える
1

Kolinkの答えに対する小さな修正:

var selectedDate = $("...").text().match(/Expires (\d+)\/(\d+)/),
    expires = new Date(selectedDate[2],selectedDate[1]-1,1,0,0,0),
    now = new Date();
if( expires.getTime() < now.getTime()) alert("past");
else alert("future");

(正規表現には引用符は必要ありません)

于 2012-07-26T15:42:23.293 に答える
0

私はそれを分割しません。私は正規表現を使用します:

var value = $('.prev-card .chzn-container .chzn-single span').text();
/\d+\/\d+/.exec(value)   //["12/2012"]
于 2012-07-26T15:33:23.173 に答える