Maximum Year in Expiry Date of Credit Card

DateMaxCredit CardBilling

Date Problem Overview


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?

Date Solutions


Solution 1 - Date

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.

Solution 2 - Date

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

Solution 3 - Date

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

Solution 4 - Date

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.

Solution 5 - Date

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>

Solution 6 - Date

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

Solution 7 - Date

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

Solution 8 - Date

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.

Solution 9 - Date

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>

Solution 10 - Date

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionArtView Question on Stackoverflow
Solution 1 - DateJohn CondeView Answer on Stackoverflow
Solution 2 - DateBryan DennyView Answer on Stackoverflow
Solution 3 - DateTom HowardView Answer on Stackoverflow
Solution 4 - DateMetaEdView Answer on Stackoverflow
Solution 5 - Dateabd3721View Answer on Stackoverflow
Solution 6 - DateLouis FerreiraView Answer on Stackoverflow
Solution 7 - DateHendrikView Answer on Stackoverflow
Solution 8 - Dateuser3347790View Answer on Stackoverflow
Solution 9 - DateAlastairView Answer on Stackoverflow
Solution 10 - DateRolloxView Answer on Stackoverflow