Validate Credit Card Number is Correctly Entered

I have a drop down menu with the choices of Visa and MC. I also have a text box that requires the credit card number. Is there a script or a way that a validator can run prior to the form being sent to the gateway that will check to make sure that the credit card number containing Visa (4) or MC (5) numbers entered actually coincide with the first digit of the credit card number?

For example, someone enters 0000-0000-0000-0000 and a script runs the validator against the chose card and the number and says, “Hey man! That’s not a valid credit card number!” Is there such a script?

I have some JavaScript that validates the check digit on a credit card number at http://javascript.about.com/library/blccard.htm

You have 2 main ways to go with this.

Do some validation on the client using JS, this is great for usability, but does not offer any security.

Do the validation on the server using PHP, less good for usability, but done correctly will assure you that no bad data gets passed to the 3rd party.

Or, do both.

To get the skinny on this go to the Advanced Search Sitepoint page and search for the keywords “credit card validation” and constrain the results to just the PHP forum and the Javascript forum to get a good cross section of discussions.

Here, for example, is one of them:

there’s a bunch of scripts out there for cc validation. its based on a formula. google it.
and as for the drop down … i always thought that was annoying as a shopper. You can strip the first number get the 4 or 5 and check if its a visa or mc

if 4 its visa
if 5 its master card