topical media & game development
professional-javascript-07-MasterCardExample.htm / htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MasterCard Example</title>
<script type="text/javascript">
function luhnCheckSum(sCardNum) {
var iOddSum = 0;
var iEvenSum = 0;
var bIsOdd = true;
for (var i=sCardNum.length-1; i >= 0; i--) {
var iNum = parseInt(sCardNum.charAt(i));
if (bIsOdd) {
iOddSum += iNum;
} else {
iNum = iNum * 2;
if (iNum > 9) {
iNum = eval(iNum.toString().split("").join("+"));
}
iEvenSum += iNum;
}
bIsOdd = !bIsOdd;
}
return ((iEvenSum + iOddSum) % 10 == 0);
}
function isValidMasterCard(sText) {
var reMasterCard = /^(5[1-5]\d{2})[\s\-]?(\d{4})[\s\-]?(\d{4})[\s\-]?(\d{4})
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.