Validate Credit Card Number (Amex,Visa,MC) When Leaving Input Field?
Posted on 2004-10-13
Hello. I have a simple form field for capturing a credit card number. At the moment it simply checks to ensure only numbers are input. Obviously I'll be able (via my merchant integration code) to authorize the card BUT I would like - somehow - to at least check (before submitting to merchant processor) that the input credit card meets the numeric algorthmic rules of credit cards (I believe there is a MOD10 (??) logic that can be run to ensure a credit card number is valid).
I'm hoping this validation of the number can be done when the user TABS or clicks (leaves) the input field ... and IF FALSE ... I need the background color of the input field to change to red.
Can this be done ("on the fly") during the form input process?
Does this make sense?
My form field:
<td width="100" align="left" valign="middle" class="styleregister3">
<strong>credit card number</strong>
<td width="132" align="left" valign="middle" class="styleregister3">
<input class="styleregister3" onkeyup='this.value=this.value.replace(/[^\d]*/gi,"");' name="pay_creditcard" type="text" width="30" maxlength="16">