Credit Card Verification with jQuery

I am trying to check credit card numbers using jQuery, but I do not want to use the check plugin, is there any other plugin for this?

+5
source share
3 answers

http://en.wikipedia.org/wiki/Luhn_algorithm

You can minimize this below to the very small size of your code.

function isCreditCard( CC )
 {                        
      if (CC.length > 19)
           return (false);

      sum = 0; mul = 1; l = CC.length;
      for (i = 0; i < l; i++)
      {
           digit = CC.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);
 }
+11
source

If you want to be sure that its valid card number, you will need to check a lot more than the Luhn number.

The Moon digit is intended only for checking transposition errors and can easily be faked with numbers such as 2222222222222222222

. , . , IIN, , . :

IIN, .

, - .

+2

... . Visa, Master Card, Discovery, american express .

https://github.com/leojavier/RegexCollection


... , , , .

for example:
- All Visa card numbers start with 4. New cards have 16 digits.
- All MasterCard numbers start with numbers from 51 to 55. All have 16 digits. etc...

index.html is a sample to show you how you can use it! Feel free to write to me if you have any questions :)

0
source

All Articles