Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Credit Card Validation

Posted on 2000-03-05
7
Medium Priority
?
307 Views
Last Modified: 2013-11-18
How credit cards are checked for their validity.What is the method adopted to verify that the credit card is valid.Is there any algorithm used?If so please explain and give an example
0
Comment
Question by:rajesh_bala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 

Expert Comment

by:cojones
ID: 2586170
No argorithm, its sent out across a connection to verify by the banks.  
0
 
LVL 84

Expert Comment

by:ozo
ID: 2586346
Do you just want to verify the checksum, or do you need to know whether the card is over its credit limit?
0
 
LVL 8

Expert Comment

by:xabi
ID: 2586677
Here you will find the code in javascript:

http://developer.netscape.com/tech/javascript/index.html

In the script CheckForm.js you will find a function to check the creditcard number.

xabi
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:ytgprasad
ID: 2643118
there is a alogorithm called LUHN algorithm for basic validation of the CARD numbers of certain Banks
0
 

Expert Comment

by:ytgprasad
ID: 2643128
for the LUHN algorithm and this site http://www.cybercash.com/cybercash/merchants/support/luhn.html may be useful, check out
0
 
LVL 8

Expert Comment

by:xabi
ID: 2645596
xabi changed the proposed answer to a comment
0
 
LVL 8

Accepted Solution

by:
xabi earned 200 total points
ID: 2645604
Here goes the code:

---------- 8< --------- 8< -----
<html>
<head>
<title>order form</title></head>
<script language="JavaScript">
<!--
function isCreditCard(st) {
 if (st.length > 19) return (false)
 sum = 0; mul = 1; l = st.length
 for (i = 0; i < l; i++) {
  digit = st.substring(l-i-1,l-i)
  tproduct = parseInt(digit ,10)*mul
  if (tproduct >= 10) sum += (tproduct % 10) + 1
  else sum += tproduct
  if (mul == 1) mul++
  else mul--
 }
 if ((sum % 10) == 0) return (true)
 else return (false)
}

function isVisa(cc) {
 if (((cc.length == 16) || (cc.length == 13)) && (cc.substring(0,1) == 4)) return isCreditCard(cc)
 return false
}

function isMasterCard(cc) {
 firstdig = cc.substring(0,1)
 seconddig = cc.substring(1,2)
 if ((cc.length == 16) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5))) return isCreditCard(cc)
 return false
}

function isAmericanExpress(cc) {
 firstdig = cc.substring(0,1)
 seconddig = cc.substring(1,2)
 if ((cc.length == 15) && (firstdig == 3) && ((seconddig == 4) || (seconddig == 7))) return isCreditCard(cc)
 return false
}

function isDinersClub(cc) {
 firstdig = cc.substring(0,1)
 seconddig = cc.substring(1,2)
 if ((cc.length == 14) && (firstdig == 3) && ((seconddig == 0) || (seconddig == 6) || (seconddig == 8))) return isCreditCard(cc)
 return false
}

function isCarteBlanche(cc) {
 return isDinersClub(cc)
}

function isDiscover(cc) {
 first4digs = cc.substring(0,4)
 if ((cc.length == 16) && (first4digs == "6011")) return isCreditCard(cc)
 return false
}

function isEnRoute(cc) {
 first4digs = cc.substring(0,4)
 if ((cc.length == 15) && ((first4digs == "2014") || (first4digs == "2149"))) return isCreditCard(cc)
 return false
}

function isJCB(cc) {
 first4digs = cc.substring(0,4)
 if ((cc.length == 16) && ((first4digs == "3088") || (first4digs == "3096") || (first4digs == "3112") || (first4digs == "3158") || (first4digs == "3337") || (first4digs == "3528"))) return isCreditCard(cc)
 return false
}

function check_values() {
 iCardType   = document.myform.CreditCard_Type.selectedIndex
 iCardNumber = document.myform.CreditCard_Number.value
 bResult = false
 if (iCardType == 0) bResult = isVisa(iCardNumber)
 if (iCardType == 1) bResult = isMasterCard(iCardNumber)
 if (iCardType == 2) bResult = isAmericanExpress(iCardNumber)
 if (iCardType == 3) bResult = isDinersClub(iCardNumber)
 if (iCardType == 4) bResult = isCarteBlanche(iCardNumber)
 if (iCardType == 5) bResult = isDiscover(iCardNumber)
 if (iCardType == 6) bResult = isEnRoute(iCardNumber)
 if (iCardType == 7) bResult = isJCB(iCardNumber)
 if (bResult == false) alert("Invalid Credit Card Number")
 return bResult
}
//-->
</script>
</head>
<body>
<form name="myform" onSubmit="return(check_values())">
<table>
  <tr>
    <td>Credit Card Type</td>
    <td>
     <select name="CreditCard_Type">
      <option>Visa</option>
      <option>MasterCard</option>
      <option>AmericanExpress</option>
      <option>DinersClub</option>
      <option>CarteBlanche</option>
      <option>Discover</option>
      <option>EnRoute</option>
      <option>JCB</option>
     </select>
    </td>
  </tr>
  <tr>
    <td>Credit Card Number</td>
    <td><input type="text" size="38" maxlength="19" name="CreditCard_Number"></td>
  </tr>
</table>
<input type="submit" value=" Submit Request">
<input type="reset" value=" Clear "> 
</form>
<br>
</body>
</html>
---------- 8< ---------- 8< -------

xabi
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question