Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display month and year selection for credit card

I am using Rails 3.1 . Here is the code I have which asks user to enter credit card expiration month and year.

  <div class="field">
    <%= f.label :expires_on, 'Expiration date' %>
    <br />
    <%= select_month nil, {add_month_numbers: true}, {name: 'creditcard[month]', id: "card_month"} %>
    <%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: 'creditcard[year]', id: "card_year"} %>
  </div>

Above code works. However the issue is that if there was a validation error then the selected expiration and month are reset.

I tried f.select_month but that is not supported.

like image 883
Nick Vanderbilt Avatar asked Dec 05 '11 13:12

Nick Vanderbilt


People also ask

Where is the month and year on a credit card?

Expiration dates appear on the front or back of a credit card in a two-digit month/year format. Credit cards expire at the end of the month written on the card. For example, a credit card's expiration date may read as 11/24, which means the card is active through the last day of November 2024.

How do you enter MM YY?

The abbreviation MM / YY corresponds to the expiration date of the credit or debit card you are going to pay with. You will find it on the front of the card, below "expires end". The term "MM" refers to the two-digit representation of the month.

How do you write the expiration date on a credit card?

Card expiration dates generally come in a two-number format, with the first number representing the month and the second showing the year. For example, 09/23 would be September of 2023.

Why does my card say invalid expiration date?

Some of the reasons you might see an "Invalid Card" error: The credit card has expired, reached its limit, or is not being authorized as a valid credit card. The credit card is not authorized for Internet transactions or has some other block in place.


1 Answers

Try something like this:

<p>
  <%= f.label :expires_on, 'Expiration date' %><br />
  <%= f.date_select :expires_on, :discard_day => true, :start_year => Date.today.year, :end_year => (Date.today.year+10), :use_month_numbers => true %>
</p>
like image 81
Pragnesh Vaghela Avatar answered Sep 18 '22 00:09

Pragnesh Vaghela