Click to See Complete Forum and Search --> : Help with credit card validation


brandy333
03-07-2003, 04:05 PM
I want to be able to validate a credit card number, card type and expiry date on a form. Note, I am a complete Javascript novice.

I have found a script at http://javascript.about.com/library/scripts/blccvalid.htm which does all I need but would prefer to use onSubmit rather than onClick to call it so I can incorporate a number of other validation routines.

I changed the onClick to onSubmit and moved it to the <form> line and it seems to do the checks OK but continues on to perform the form action rather than set focus back at the offending field.

Can anyone help me to get this working the way I want?

brandy333
03-07-2003, 05:48 PM
onSubmit="validCCForm(this.form.ccType,this.form.ccNum,this.form.ccExp)"

Jona
03-07-2003, 05:49 PM
I could be wrong but... aren't you supposed to put spaces after each comma?

brandy333
03-07-2003, 05:56 PM
As I mentioned, the verification works fine, it's just that it continues with the form action even after an error is detected.

Nedals
03-07-2003, 05:57 PM
jona, It doesn't matter. Either way. I use spaces because it's easier to read.

brandy333
Add a 'return false' after you detect an error, that should stop the form processing.

Jona
03-07-2003, 06:00 PM
Oh... to both of you :D