From: Tim Becker on
> > JCB 3528-2589 Length: 16

should be 3528-3589, obviously.

> > Diners 3000-3029, 3040-3059, 36, 3815-3889, 389 Length: 14

> Wow, those are some broad ranges.

Well, those ranges DO include Carte Blanche :) I haven't seen a
physical Diners Card in at least 20 years to be honest, not sure who
still uses them.

If you think those ranges are broad, the last UK-Switch/Solo table I
had has over 180 card prefixes with different card lengths...

From: John Joyce on

On Apr 27, 2007, at 10:37 PM, Tim Becker wrote:

>> > JCB 3528-2589 Length: 16
>
> should be 3528-3589, obviously.
>
>> > Diners 3000-3029, 3040-3059, 36, 3815-3889, 389 Length: 14
>
>> Wow, those are some broad ranges.
>
> Well, those ranges DO include Carte Blanche :) I haven't seen a
> physical Diners Card in at least 20 years to be honest, not sure who
> still uses them.
>
> If you think those ranges are broad, the last UK-Switch/Solo table I
> had has over 180 card prefixes with different card lengths...
>
My grandmother used to have a Diners Club card. Last time I saw that
was about 20 years ago too.
But of the cards accepted here in Tokyo, Diners Club is one that is
often listed! (in bars and restaurants of course)

Oh, I can only imagine. Processing cards with less deeply thought out
numbering schemes. The big boys planned that stuff back when
computing power was a premium.

From: Matthew Moss on
> +============+=============+===============+
> | Card Type | Begins With | Number Length |
> +============+=============+===============+
> | AMEX | 34 or 37 | 15 |
> +------------+-------------+---------------+
> | Discover | 6011 | 16 |
> +------------+-------------+---------------+
> | MasterCard | 51-55 | 16 |
> +------------+-------------+---------------+
> | Visa | 4 | 13 or 16 |
> +------------+-------------+---------------+

So is a card number like "4012 3456 7890" a valid Unknown, or an invalid Visa?
Similarly, for Unknown, should we accept any length, or go for the common 16?

From: James Edward Gray II on
On Apr 27, 2007, at 12:58 PM, Matthew Moss wrote:

>> +============+=============+===============+
>> | Card Type | Begins With | Number Length |
>> +============+=============+===============+
>> | AMEX | 34 or 37 | 15 |
>> +------------+-------------+---------------+
>> | Discover | 6011 | 16 |
>> +------------+-------------+---------------+
>> | MasterCard | 51-55 | 16 |
>> +------------+-------------+---------------+
>> | Visa | 4 | 13 or 16 |
>> +------------+-------------+---------------+
>
> So is a card number like "4012 3456 7890" a valid Unknown, or an
> invalid Visa?

Visa Invalid

Always match the type first.

> Similarly, for Unknown, should we accept any length, or go for the
> common 16?

Unknown is for any type that doesn't match, so it could be any length.

James Edward Gray II


From: Matthew Moss on
So I took this as an opportunity to try doing a little TDD, something
which is appealing but I've never really tried. It _is_ fun to see
failure first and then fix. =) There are probably other tests I
could have included, but here is a start, in case people want to check
a few numbers or add more tests:

Obviously, you may need to change this to match your solution...


require "test/unit"
require "ccard"


class CreditCardCheckTest < Test::Unit::TestCase

def test_valid_numbers
assert CreditCard.new("4408041234567893").valid?
assert CreditCard.new("6011111111111117").valid?
end

def test_invalid_nubers
assert !CreditCard.new("4417123456789112").valid?
end


def test_valid_numbers_with_spaces
assert CreditCard.new("4408 0412 3456 7893").valid?
assert CreditCard.new("6011 1111 1111 1117").valid?
end

def test_invalid_nubers_with_spaces
assert !CreditCard.new("4417 1234 5678 9112").valid?
end

def test_valid_types
assert_equal CreditCard.new("4408041234567893").type, :visa
assert_equal CreditCard.new("4408 0412 3456 7893").type, :visa
assert_equal CreditCard.new("6011 1111 1111 1117").type, :discover
assert_equal CreditCard.new("123456789").type, :unknown
end

def test_invalid_types
assert_nil CreditCard.new("4408 0412 3456 789").type
end

end