Maximum Year in Expiry Date of Credit Card

2019-03-07 20:45发布

问题:

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

For instance:

  • Basecamp: +15 years (2025)
  • Amazon: +20 years (2030)
  • Paypal: +19 years (2029)

What is the reasonable maximum here? Are there any official guidelines?

回答1:

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.



回答2:

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).



回答3:

As a theoretical upper limit, I propose that you do not need to consider more than the expected lifespan of the cardholder. Wikipedia does this in their editorial standards for biographies of living persons:

Any individual born less than 115 years ago is covered by this policy unless a reliable source has confirmed the individual's death. People over 115 years old are presumed dead unless listed at oldest people.

So, in your code, look up the current year, add 115, and use that as your theoretical upper limit to the credit card expiration date. You'll never have to touch that code again.



回答4:

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>



回答5:

Good call, @Alistair.

Here's the month and year generation in ASP.NET MVC. Add this to your viewmodel:

public IList<SelectListItem> Months = new List<SelectListItem>() { 
    new SelectListItem() { Text="Jan", Value="01" },
    new SelectListItem() { Text="Feb", Value="02" },
    new SelectListItem() { Text="Mar", Value="03" },
    new SelectListItem() { Text="Apr", Value="04" },
    new SelectListItem() { Text="May", Value="05" },
    new SelectListItem() { Text="Jun", Value="06" },
    new SelectListItem() { Text="Jul", Value="07" },
    new SelectListItem() { Text="Aug", Value="08" },
    new SelectListItem() { Text="Sep", Value="09" },
    new SelectListItem() { Text="Oct", Value="10" },
    new SelectListItem() { Text="Nov", Value="11" },
    new SelectListItem() { Text="Dec", Value="12" },
};
public IEnumerable<SelectListItem> Years
{
    get
    {
        return new SelectList(Enumerable.Range(DateTime.Today.Year, 15));
    }
}

And this to your view:

<fieldset>
    <legend>Card expiration</legend>
    <div style="float: left;">
        <div class="editor-label">
            @Html.LabelFor(model => model.ExpirationMonth)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.ExpirationMonth, Model.Months)
            @Html.ValidationMessageFor(model => model.ExpirationMonth)
        </div>
    </div>
    <div style="float: left;">

        <div class="editor-label">
            @Html.LabelFor(model => model.ExpirationYear)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.ExpirationYear, Model.Years)
            @Html.ValidationMessageFor(model => model.ExpirationYear)
        </div>
    </div>
</fieldset>


回答6:

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.



回答7:

<?php 
$y = gmdate("Y");
$x = 20;
$max = ($y + $x);
while ($y <= $max) {
echo "<option value='$y'>$y</option>";
$y = $y + 1;
}
?>


回答8:

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";
    }
?>


回答9:

After reading the OP's upper validity of 20 years for Amazon, I wrote this simple solution in PHP:

<select name='Expiry-Year'>
    <option value="">yy</option>
    <?php
    for($i=0;$i<21;$i++){
        echo "<option value='".(date('Y')+$i)."'>".(date('y')+$i)."</option>\n";
    }
    ?>
</select>

This has greatly reduced the number of these new-year requests to remove last year from a form.

A leaner version of the loop runs ~twice as quickly:

<select name='Expiry-Year'>
    <option value="">yy</option>
    <?php
    for($i=date('Y');$i<date('Y')+21;$i++){
        echo "<option value='".$i."'>".substr($i,2)."</option>\n";
    }
    ?>
</select>


回答10:

<script type="text/javascript">
  var select = $(".card-expiry-year"),
  year = new Date().getFullYear();

  for (var i = 0; i < 20; i++) {
      select.append($("<option value='"+(i + year)+"' "+(i === 0 ? "selected" : "")+">"+(i + year)+"</option>"))
  }
</script>