How to put Javascript and php validation for Credit card?

Step 1: First create creditcard.php file and use the below code.

  $credit_card_cc_owner = $_POST['credit_card_cc_owner'];
  $cardnumber = $_POST['credit_card_cc_number'];
  $cardname = $_POST['credit_card_type'];
  $cardcvv = $_POST['credit_card_cvv'];
  $card_cc_expires_month = $_POST['credit_card_cc_expires_month'];
  $card_cc_expires_year = $_POST['credit_card_cc_expires_year'];
  if (strlen($credit_card_cc_owner) < 3)
    $error = true;
    $Errormessage.="The Owner\'s name of the credit card must be at least 3 characters.
  if (strlen($cardnumber) < 13)
      $error = true;
      $Errormessage.="The Credit Card number must be at least 13 characters.
  if (strlen($credit_card_cvv) < 3)   {       $error = true;       $Errormessage.="The Credit Card cvv number must be at least 3 characters. ";   }   if(!tep_validateCC($cardnumber,$cardname))   {       $error = true;       $Errormessage.="Please make sure that you entered a valid Credit Card Number. ";   }   if(!tep_CheckCVV($cardnumber,$cardcvv))   {       $error = true;       $Errormessage.="Please make sure that you entered valid CVV Number. ";  }  if(!tep_CheckCreditCardExpirationDate($card_cc_expires_month,$card_cc_expires_year))  {       $error = true;       $Errormessage.="Please Select Valid Date";  }  if($error==false)  	$Successmessage="Your Credit card is valid"; } ?>
Credit Card Validation Java+PHP Example
<script type="text/javascript" language="javascript" src="creditcard.js"></script></pre>
<form action="" method="post" name="creditcard" onsubmit="return check_form(creditcard);">
<table width="30%" border="0" cellspacing="0" cellpadding="2" align="center">
<td colspan="2"><?php if($error==1) { echo '<span style="color: #ff0000;">'.$Errormessage.'</span>';
 } else { echo '<span style="color: #76c776;">'.$Successmessage.'</span>';} ?></td>
<td class="main" width="180">Credit Card Owner:</td>
<td class="main"><input type="text" name="credit_card_cc_owner" /></td>
<td class="main" width="180">Credit Card Type:</td>
<td class="main"><select name="credit_card_type"><option value="Amex">Amex</option><option value="Mastercard">Mastercard</option><option value="Visa">Visa</option></select></td>
<td class="main" width="180">Credit Card Number:</td>
<td class="main"><input type="text" name="credit_card_cc_number" /></td>
<td class="main" width="180">Credit Card Expiry Date:</td>
<td class="main"><select name="credit_card_cc_expires_month"><option value="01">January</option><option value="02">February</option><option value="03">March</option><option value="04">April</option><option value="05">May</option><option value="06">June</option><option value="07">July</option><option value="08">August</option><option value="09">September</option><option value="10">October</option><option value="11">November</option><option value="12">December</option></select> <select name="credit_card_cc_expires_year"><option value="2011">2011</option><option value="2012">2012</option><option value="2013">2013</option><option value="2014">2014</option><option value="2015">2015</option><option value="2016">2016</option><option value="2017">2017</option><option value="2018">2018</option><option value="2019">2019</option><option value="2020">2020</option></select></td>
<td class="main" width="180">CVV number</td>
<td class="main"><input type="text" name="credit_card_cvv" size="4," maxlength="4" /></td>
<td class="main" width="180"></td>
<td class="main"><input type="submit" name="submit" value="Submit" /></td>

Step 2: You can download creditcard_valid.php file:  creditcard_valid.php

Step 3: You can download creditcard.js file : creditcard.js

Step 4: Now run your creditcard.php file and you can enjoy the javascript and PHP Caredit card validation on your site.

Speak Your Mind

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: