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


clonmelog
02-18-2005, 06:13 PM
Hi,

im trying to setup validation for a customers cc details. how would i do this to the following textfields?

<td width="65%"> <select name="C_CcType" id="C_CcType">
<option selected>Visa</option>
<option>MasterCard</option>
<option>American Express</option>
</select> </td>
</tr>
<tr>
<td width="35%"><font color="#FFFFFF" face="Times New Roman, Times, serif">Card
Number</font></td>
<td width="65%"> <input type="text" name="C_CcNum" class="textBoxNormal" onfocus="this.className='textBoxActive'" onblur="this.className='textBoxNormal'">
</td>
</tr>
<tr>
<td width="35%"><font color="#FFFFFF" face="Times New Roman, Times, serif">Expiry
Date</font></td>
<td width="65%"> <input type="text" name="C_ExpD" class="textBoxNormal" onfocus="this.className='textBoxActive'" onblur="this.className='textBoxNormal'"> </td>
</tr>
<tr>
<td width="35%"><font color="#FFFFFF" face="Times New Roman, Times, serif">Sec
Code </font></td>
<td width="65%"> <input type="text" name="C_Sec" class="textBoxNormal" onfocus="this.className='textBoxActive'" onblur="this.className='textBoxNormal'"> </td>
</tr>
<tr>
<td colspan="2">&nbsp; </td>
</tr>
</table>

BeachSide
02-18-2005, 07:01 PM
Are you trying to do this client side or server side? If client side you would be better off with JavaScript (not a very good idea though) or you can do it server side with php and a regex that validates that at least it is a possible valid cc# that was entered.

Something like...

'/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{14}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$/',$

pyro
02-19-2005, 10:10 AM
Do a google search for LUHN/Mod 10 algorithm... that's a start.