Forum Moderators: buckworks

Message Too Old, No Replies

Credit Card number format

validating user input

         

Reflection

6:34 pm on Jan 15, 2004 (gmt 0)

10+ Year Member



Apologies if this has been asked before, probably has, but I couldnt find the information.

I want to make sure that the user has entered a credit card number that is in the correct format (length etc.) for VISA and Mastercard.

Can anyone point me in the right direction/what I should be looking for.

Thanks.

wackal

8:14 pm on Jan 15, 2004 (gmt 0)

10+ Year Member



the cc number should be exactly 16 characters, all numeric, and begin with a 4 or 5.

pete_m

10:54 am on Jan 16, 2004 (gmt 0)

10+ Year Member



Hi reflection

There's actually quite a variety of types, lengths, starting numbers out there. You can also use the Luhn algorithm (also known as Mod 10) to check that a number is valid.
Do a search on google for "credit card number validation" - there are loads of pages out there.

Reflection

7:07 pm on Jan 16, 2004 (gmt 0)

10+ Year Member



Thanks guys.

One more question related to CC's. In terms of expiration dates ,to be on the safe side, how many years into the future should you provide for the user?

wackal

7:38 pm on Jan 16, 2004 (gmt 0)

10+ Year Member



I just use a text field for the expiration date, but I think 5 years is plenty. Just don't forget that you will have to go back into the code every year and update it.

defanjos

7:57 pm on Jan 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One more question related to CC's. In terms of expiration dates ,to be on the safe side, how many years into the future should you provide for the user?

I've charged customers CCs with an expiration date of xx/2020, so I would say, go many years in the future.