Skip to content

aperkins81/ccvalid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ccvalid

Validates credit card numbers.

Usage:

ruby ccvalid.rb

Testing:

ruby tester.rb

Output:

$ ruby ccvalid.rb
VISA: 4111111111111111       (valid)
VISA: 4111111111111          (invalid)
VISA: 4012888888881881       (valid)
AMEX: 378282246310005        (valid)
Discover: 6011111111111117   (valid)
MasterCard: 5105105105105100 (valid)
MasterCard: 5105105105105106 (invalid)
Unknown: 9111111111111111    (invalid)

Tests:

Valid card with spaces should be valid............................ PASS (t == t)
Invalid card with spaces should not be valid...................... PASS (f == f)
Valid card should be valid........................................ PASS (t == t)
Invalid card should not be valid.................................. PASS (f == f)
Valid card should be valid........................................ PASS (t == t)
Valid card should be valid........................................ PASS (t == t)
Valid card should be valid........................................ PASS (t == t)
Valid card should be valid........................................ PASS (t == t)
Invalid card should not be valid.................................. PASS (f == f)
Invalid card should not be valid.................................. PASS (f == f)
Card starting with 50 should not be MasterCard.................... PASS (f == f)
Card starting with 51 should be MasterCard........................ PASS (t == t)
Card starting with 52 should be MasterCard........................ PASS (t == t)
Card starting with 53 should be MasterCard........................ PASS (t == t)
Card starting with 54 should be MasterCard........................ PASS (t == t)
Card starting with 55 should be MasterCard........................ PASS (t == t)
Card starting with 56 should not be MasterCard.................... PASS (f == f)
Card starting with 55 should be MasterCard........................ PASS (t == t)
Card starting with 5 should not be MasterCard..................... PASS (f == f)
Card starting with 6 should not be MasterCard..................... PASS (f == f)
Card starting with 7 should not be MasterCard..................... PASS (f == f)
Card starting with 8 should not be MasterCard..................... PASS (f == f)
Card starting with 9 should not be MasterCard..................... PASS (f == f)
Card starting with 0 should not be MasterCard..................... PASS (f == f)
Card starting with 1 should not be MasterCard..................... PASS (f == f)
Card starting with 2 should not be MasterCard..................... PASS (f == f)
Card starting with 3 should not be MasterCard..................... PASS (f == f)
Card starting with 4 should not be MasterCard..................... PASS (f == f)
Card starting with 51 should be MasterCard........................ PASS (t == t)
Card starting with 3 should not be Visa........................... PASS (f == f)
Card starting with 4 should be Visa............................... PASS (t == t)
Card starting with 5 should not be Visa........................... PASS (f == f)
Card starting with 6 should not be Visa........................... PASS (f == f)
Card starting with 1 should not be Visa........................... PASS (f == f)
Card starting with 2 should not be Visa........................... PASS (f == f)
Card starting with 3 should not be Visa........................... PASS (f == f)
Card starting with 4 should be Visa............................... PASS (t == t)
Card starting with 5 should not be Visa........................... PASS (f == f)
Card starting with 6 should not be Visa........................... PASS (f == f)
Card starting with 7 should not be Visa........................... PASS (f == f)
Card starting with 8 should not be Visa........................... PASS (f == f)
Card starting with 9 should not be Visa........................... PASS (f == f)
Card starting with 0 should not be Visa........................... PASS (f == f)
Card starting with 33 should not be AMEX.......................... PASS (f == f)
Card starting with 34 should be AMEX.............................. PASS (t == t)
Card starting with 35 should not be AMEX.......................... PASS (f == f)
Card starting with 36 should not be AMEX.......................... PASS (f == f)
Card starting with 37 should be AMEX.............................. PASS (t == t)
Card starting with 38 should not be AMEX.......................... PASS (f == f)
Card starting with 39 should not be AMEX.......................... PASS (f == f)
Card starting with 30 should not be AMEX.......................... PASS (f == f)
Card starting with 31 should not be AMEX.......................... PASS (f == f)
Card starting with 32 should not be AMEX.......................... PASS (f == f)
Card starting with 3 should not be AMEX........................... PASS (f == f)
Card starting with 7 should not be AMEX........................... PASS (f == f)
Card starting with 2 should not be AMEX........................... PASS (f == f)
Card starting with 8 should not be AMEX........................... PASS (f == f)
Card starting with 4 should not be AMEX........................... PASS (f == f)
Card starting with 5 should not be AMEX........................... PASS (f == f)
Card starting with 6 should not be AMEX........................... PASS (f == f)
Card starting with 9 should not be AMEX........................... PASS (f == f)
Card starting with 0 should not be AMEX........................... PASS (f == f)
Card starting with 1 should not be AMEX........................... PASS (f == f)
Card starting with 6010 should not be Discover.................... PASS (f == f)
Card starting with 6011 should be Discover........................ PASS (t == t)
Card starting with 6012 should not be Discover.................... PASS (f == f)
Card starting with 601 should not be Discover..................... PASS (f == f)
Card starting with 60 should not be Discover...................... PASS (f == f)
Card starting with 6 should not be Discover....................... PASS (f == f)
Card starting with 7 should not be Discover....................... PASS (f == f)
Card starting with 8 should not be Discover....................... PASS (f == f)
Card starting with 9 should not be Discover....................... PASS (f == f)
Card starting with 0 should not be Discover....................... PASS (f == f)
Card starting with 1 should not be Discover....................... PASS (f == f)
Card starting with 2 should not be Discover....................... PASS (f == f)
Card starting with 3 should not be Discover....................... PASS (f == f)
Card starting with 4 should not be Discover....................... PASS (f == f)
Card starting with 5 should not be Discover....................... PASS (f == f)
4111111111111111 is a valid luhn number........................... PASS (t == t)
4111111111111112 is an invalid luhn number........................ PASS (f == f)
378282246310005 is a valid AMEX card.............................. PASS (t == t)
378282246310006 is an invalid AMEX card........................... PASS (f == f)
378282246310004 is an invalid AMEX card........................... PASS (f == f)
6011111111111117 is a valid Discover card......................... PASS (t == t)
6011111111111118 is an ivalid Discover card....................... PASS (f == f)
601111111111116 is an invalid Discover card....................... PASS (f == f)
5105105105105100 is a valid MasterCard............................ PASS (t == t)
5105105105105101 is an invalid MasterCard......................... PASS (f == f)
510510510510510 is an invalid MasterCard.......................... PASS (f == f)
4111111111111111 is a valid VISA.................................. PASS (t == t)
4111111111111112 is an invalid VISA............................... PASS (f == f)
411111111111111 is an invalid VISA................................ PASS (f == f)
4408041234567893 is a valid VISA.................................. PASS (t == t)
4408041234567894 is an invalid VISA............................... PASS (f == f)
4408041234567892 is an invalid VISA............................... PASS (f == f)
Card starting with 4 is VISA...................................... PASS (t == t)
Card starting with 5 is not VISA.................................. PASS (f == f)
Card starting with 34 is AMEX..................................... PASS (t == t)
Card starting with 37 is AMEX..................................... PASS (t == t)
Card starting with 38 is not AMEX................................. PASS (f == f)
Card starting with 3 is not AMEX.................................. PASS (f == f)
Card starting with 6011 is Discover............................... PASS (t == t)
Card starting with 6012 is not Discover........................... PASS (f == f)
Card starting with 601 is not Discover............................ PASS (f == f)
Card starting with 60 is not Discover............................. PASS (f == f)
Card starting with 6 is not Discover.............................. PASS (f == f)
Card starting with 51 is MasterCard............................... PASS (t == t)
Card starting with 52 is MasterCard............................... PASS (t == t)
Card starting with 53 is MasterCard............................... PASS (t == t)
Card starting with 54 is MasterCard............................... PASS (t == t)
Card starting with 55 is MasterCard............................... PASS (t == t)
Card starting with 56 is not MasterCard........................... PASS (f == f)
Card starting with 5 is not MasterCard............................ PASS (f == f)
Card starting with 57 is not MasterCard........................... PASS (f == f)
Card starting with 50 is not MasterCard........................... PASS (f == f)

Tests: 115.  Passes:  (100%).  Failures: 0 (0%)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages