Название категории

Credit card tape

JavaScript : HTML Form - Credit Card Number validation

Credit card tape Credit card tape

A validating credit card is an important point while receiving payment through an HTML form. In this page, we have discussed how to validate a credit card number (in a different format) using JavaScript. There are various companies in financial market offer credit cards. But there is no common format in the credit card numbering system, it varies company to company. We are not sure that all the formats which we have discussed here are correct because time to time a company can change their numbering format. You can easily change a format with simply modify the regular expression which we have used for various cards. Here are some format of some well-known credit cards.

  • American Express :- Starting with 34 or 37, length 15 digits.
  • Visa :- Starting with 4, length 13 or 16 digits.
  • MasterCard :- Starting with 51 through 55, length 16 digits.
  • Discover :- Starting with 6011, length 16 digits or starting with 5, length 15 digits.
  • Diners Club :- Starting with 300 through 305, 36, or 38, length 14 digits.
  • JCB :- Starting with 2131 or 1800, length 15 digits or starting with 35, length 16 digits.

Following code blocks contain actual codes for the said credit cards validations. We have kept the CSS code part common for all the validations.

Validate a American Express credit card

Following example validate a American Express credit card starting with 34 or 37, length 15 digits.

Credit card tape

Following example validate a Visa card starting with 4, length 13 or 16 digits.

Credit card tape

Following example validate a MasterCard starting with 51 through 55, length 16 digits.

Credit card tape

Following example validate a Discover Card starting with 6011, length 16 digits or starting with 5, length 15 digits.

Credit card tape

Following example validate a Diners Club card starting with 300 through 305, 36, or 38, length 14 digits.

Credit card tape

Following example validate a JCB card starting with 2131 or 1800, length 15 digits or starting with 35, length 16 digits.

Credit card tape

Credit card tapeDownload the Validation code from here.

Other JavaScript Validation :


credit card tape

Why do online retailers ask for the type of card before you enter the number?

This information is coded into the card number itself, so it is redundant.

For example, any card that starts with a 4 is a Visa.

51 through 55 is MasterCard

34 or 37 is American Express.

There are quite a few longer ones, but the principle is the same: The information is in the card number.

The card networks are different. Depending on the type selected, the call to the different networks are identified.

Now the website that is asking the user to input the number can parse the number and then decide as to which network it belongs and accordingly invoke the respective call.

However this would go against the principal of accepting the user input and making the right call. From a security standpoint, the website is not supposed to store/process your card info, but take it as is and pass it on for authentication to the respective network. Hence its a more clean design where by user is asked to input the type of card, and whatever value the user enters is passed on to the said network. It is now for the network to validate it and return Pass/Fail.

Plus from a UI point of you, it shows the user easily what cards are supported for payment on the said gateway. Yes this information can also be put else where, but there is no guarantee that the user would read it. Forcing him to select a value make sure that he is using a right card that is supported by the website.


How To Detect Credit Card Type And Validate Numbers Using jQuery

Credit card tape

We all are working on shopping cart application or any other website having transaction using credit card. We always required client side validation to verify credit card type or user using valid card number. In this tutorial we are going to show you that how to detect credit card type and validate credit card number using jQuery. It will display the type of detected credit card and calculate the length of card number by its type.

To achieve this we are using jQuery Credit Card validator library.