jQuery credit card validator – Creditly.js

Creditly.js is a jQuery credit card validator plugin – create and validate credit card form inputs in an easy way.

Well done jQuery credit card validator

Creditly.js is a jQuery plugin for creating an input masked form with input validation for your customers that makes it easier to input credit card information.

Creditly.js is a solution, that gives everything we need to create an intuitive credit card form. We can create such a form in few moments.

Creditly.js - jQuery credit card validator in action
Creditly.js – jQuery credit card validator in action

How to use

To integrate, just add the necessary files:

<script type="text/javascript" src="creditly.js"></script>

<link rel="stylesheet" href="creditly.css">

Then copy the HTML from the theme you’d like to use (check the HTML files in src/themes folder).

Initialize with JS:

    var creditly = Creditly.initialize(
        '.creditly-wrapper .expiration-month-and-year',
        '.creditly-wrapper .credit-card-number',
        '.creditly-wrapper .security-code',
        '.creditly-wrapper .card-type');


Currently the following themes are supported:

– blue_theme

– gray_theme

In fact it’s not hard to crate our own themes.

Submitting a form

When a user wants to submit a form, Creditly.js can be used to perform validation on the fields, and return an output of the results if the validation succeeded.

For example:

var creditly = Creditly.initialize(
    '.creditly-wrapper .expiration-month-and-year',
    '.creditly-wrapper .credit-card-number',
    '.creditly-wrapper .security-code',
    '.creditly-wrapper .card-type');
$(".creditly-card-form .submit").click(function(e) {
  var output = creditly.validate();
  if (output) {
    // Do something with your credit card output.

The first part of the above example instantiates the creditly object in the creditly variable. Then, whenever the .creditly-card-form .submit button is clicked, we perform a validation by using creditly.validate().

Errors of validation

A jQuery event will be triggered on the body element, and can be accessed as:

  function(e, data) {
    alert(data["messages"].join(", "));

Note: if jQuery does not exist on the page, then a MessageEvent will be fired on the body element and can be accessed in following way:

  function(e) {
    alert(e.data["messages"].join(", "));
}, false);

Simple and clever.

License: MIT



Get jQuery credit card validator from GitHub:


You may also like:

Ideal Forms 3: build and validate responsive HTML5 forms!

Progression.js – jQuery form progress indicator