Created
February 2, 2015 16:38
-
-
Save hightemp/3862e50023b45b1b7035 to your computer and use it in GitHub Desktop.
Credit card number checker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fnValidCreditCardNumber( objFormField ) | |
{ | |
var nSum = 0; | |
var nMultiplier = 1; | |
var nIndex; | |
var sDigit; | |
var nProduct; | |
var sCreditCardAccountNumber = objFormField.value; | |
var nLength = objFormField.value.length; | |
if( ( nLength < 13 ) || ( sCreditCardAccountNumber.length > 19 ) ) | |
return(false); | |
for( nIndex = 0; nIndex < nLength; ++nIndex ) | |
{ | |
sDigit = sCreditCardAccountNumber.substring( (nLength-nIndex-1) , (nLength-nIndex) ); | |
nProduct = parseInt(sDigit,10) * nMultiplier; | |
if( nProduct >= 10 ) nSum += ( nProduct % 10) + 1; | |
else nSum += nProduct; | |
if( nMultiplier == 1 ) ++nMultiplier; | |
else --nMultiplier; | |
} | |
if( ( nSum % 10) == 0 ) return(true); | |
else return(false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment