Maximum Year in Expiry Date of Credit Card

前端 未结 10 875
情话喂你
情话喂你 2021-01-30 02:30

Various online services have different values for maximum year of expiry, when it comes to Credit Cards.

For instance:

  • Basecamp: +15 years (2025)
相关标签:
10条回答
  • 2021-01-30 03:13

    If you want a solution that does not yield three-digit years 2100+ you must modulo the date, accordingly you must fill with leading zero for xx00-xx09 years to not get single digit years.

    This will be very important starting in 2080.

    <?php
        for($i=0;$i<=20;$i++){
            $aktDate = sprintf("%02d", ((date('y')+$i)%100));
            echo "<option value=\"{$aktDate}\">{$aktDate}</option>\n";
        }
    ?>
    
    0 讨论(0)
  • 2021-01-30 03:14

    Here's a sampling of the top US online retailers:

    RETAILER        WINDOW IN YEARS
    Amazon          20
    Walmart         10
    Apple           NA (TEXT FIELD)
    Home Depot      19
    Best Buy        10
    Target          NA (TEXT FIELD)
    eBay            NA (TEXT FIELD)
    Google          19
    
    0 讨论(0)
  • 2021-01-30 03:16

    There is no official guideline as the credit card issuers can choose each when the cards they issue will expire. In fact they have been issuing cards for longer and longer periods of time. If you're trying to determine how far out into the future you should accommodate expiration dates for, err on the safe side and give your customers many years to choose from. That way you future proof your application.

    FYI, many credit card issuers do not use the expiration date when determining whether or not to approve a credit card purchase. So if you're worried about an incorrect date being provided the processor will ultimately have the final say on whether the transaction is approved or not so I wouldn't worry about it.

    July 2017: Just had an end user with a card that expired almost 50 years from now.

    0 讨论(0)
  • 2021-01-30 03:17

    I would either dynamically add +15-20 years to the current date's year OR provide a textbox input for the year (which personally I find faster to type the two digits in than to scroll through a list of years).

    0 讨论(0)
  • 2021-01-30 03:22

    While the second example runs twice as quickly as the first you are still getting the date and extracting the year from it 20 times rather than 40 times. A better unrolling of the loop is:

    $StartDate=date('Y');
    $EndDate=$StartDate+21;
    for($i=$StartDate;$i<$EndDate;$i++){
        echo "<option value='".$i."'>".substr($i,2)."</option>\n";
    

    That will be about 20 times faster than the twice as fast example and also addresses a minor bug in the original code in that the year could change from one fetching of the date to the next leading to unexpected, though in this case harmless, results.

    0 讨论(0)
  • 2021-01-30 03:25

    Here is a Javascript code snippet you can use to display a customizable list of upcoming years for CC validation:

        var yearsToShow = 20;
        var thisYear = (new Date()).getFullYear();
        for (var y = thisYear; y < thisYear + yearsToShow; y++) {
          var yearOption = document.createElement("option");
          yearOption.value = y;
          yearOption.text = y;
          document.getElementById("expYear").appendChild(yearOption);
        }
              <label for="expiration">Expiration Date</label>
              <span id="expiration">
                <select id="expMonth" name="expMonth">
                  <option disabled="true">Month</option>
                  <option value="1">Jan</option>
                  <option value="2">Feb</option>
                  <option value="3">Mar</option>
                  <option value="4">Apr</option>
                  <option value="5">May</option>
                  <option value="6">Jun</option>
                  <option value="7">Jul</option>
                  <option value="8">Aug</option>
                  <option value="9">Sep</option>
                  <option value="10">Oct</option>
                  <option value="11">Nov</option>
                  <option value="12">Dec</option>
                </select>
                <select id="expYear" name="expYear">
                </select>
              </span>

    0 讨论(0)
提交回复
热议问题