Monday, May 6, 2013

Credit Card validation with jQuery

This is a lightweight and easy to implement credit card validation with jQuery.
With jQuery, server processing is not required; and all the complexities are hide.
another way to validate credit card is with regular expression.

There is only 3 steps to validate credit card number with jQuery.


Steps:
1. Install jQuery and jQuery validation plugin
<script src="http://code.jquery.com/jquery-latest.js" />

<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js" />
for project already installed jQuery, first line is not required.

2. Create form and textbox to input credit card number.
<form id="myform">
  <label for="ccard">creditcard : </label>
  <input name="ccard" />
</form>

3. Create jQuery validation script.
<script>
$(document).ready(function(){
  $("#myform").validate({
    rules: {
      ccard: {
        creditcard: true
      }
    }
  });
});
</script>



Done!!


No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...