Card - check out the demo
A better credit card form in one line of code
Card will take any credit card form and make it the best part of the checkout process (without you changing anything). Everything is created with pure CSS, HTML, and Javascript — no images required.
Usage (without jQuery)
To use, you'll need to include the Card JavaScript files into your HTML, no CSS link is necessary as the JavaScript file does this for you. You can find the necessary file at /dist/card.js
and include it in your HTML like so.
<script src="/path/to/card.js"></script>
Once you've included those files, you can initialize Card.
var card = new Card({
form: 'form',
container: '.card-wrapper',
formSelectors: {
numberInput: 'input#number',
expiryInput: 'input#expiry',
cvcInput: 'input#cvc',
nameInput: 'input#name'
},
width: 200,
formatting: true,
messages: {
validDate: 'valid\ndate',
monthYear: 'mm/yyyy',
},
placeholders: {
number: '•••• •••• •••• ••••',
name: 'Full Name',
expiry: '••/••',
cvc: '•••'
},
masks: {
cardNumber: '•'
},
debug: false
});
Installing card from bower
If you're using bower, you can install card.js with:
bower install card --save
Installing card from npm
If you're using npm, you can install card.js with:
npm install --save card
var $ = require("jquery");
// The current card.js code does not explictly require jQuery, but instead uses the global, so this line is needed.
window.jQuery = $;
var card = require("card");
Using multiple inputs for one field
Card can be used in forms where you have multiple inputs that render to a single field (i.e. you have a first and last name input). To use Card with this functionality, just pass in a selector that selects the fields in the correct order. For example,
<html>
<body>
<div class='card-wrapper'></div>
<script src="/path/to/card.js"></script>
<form>
<input type="text" name="number">
<input type="text" name="first-name"/>
<input type="text" name="last-name"/>
<input type="text" name="expiry"/>
<input type="text" name="cvc"/>
</form>
<script>
var card = new Card({
form: 'form',
container: '.card-wrapper',
formSelectors: {
nameInput: 'input[name="first-name"], input[name="last-name"]'
}
});
</script>
</body>
</html>
Rendering with different initial card placeholders
Card renders with default placeholders for card name
, number
, expiry
, and cvc
. To override these placeholders, you can pass in a placeholders
object.
<html>
<body>
<div class='card-wrapper'></div>
<script src="/path/to/card.js"></script>
<form>
<input type="text" name="number">
<input type="text" name="name"/>
<input type="text" name="expiry"/>
<input type="text" name="cvc"/>
</form>
<script>
var card = new Card({
form: 'form',
container: '.card-wrapper',
placeholders: {
number: '**** **** **** ****',
name: 'Arya Stark',
expiry: '**/****',
cvc: '***'
}
});
</script>
</body>
</html>
Translation
To render the card with the strings in a different language, you can pass in a messages
object.
<html>
<body>
<div class='card-wrapper'></div>
<script src="/path/to/card.js"></script>
<form>
<input type="text" name="number">
<input type="text" name="name"/>
<input type="text" name="expiry"/>
<input type="text" name="cvc"/>
</form>
<script>
var card = new Card({
form: 'form',
container: '.card-wrapper',
messages: {
validDate: 'expire\ndate',
monthYear: 'mm/yy'
}
});
</script>
</body>
</html>
Using with jQuery
To use with jQuery, you'll need to include the jquery.card.js
file into your HTML. You can find the necessary file at /dist/jquery.card.js
and include it in your HTML like so.
<script src="/path/to/jquery.card.js"></script>
Once you've included those files, you can initialize Card with jQuery.
$('form').card({
container: '.card-wrapper',
});
Using with other javascript libraries
Card has wrappers that make it easy to use with other javascript libraries:
Angular (1.x Currently)
Ember
React
Development
To contribute, follow this steps:
$ git clone --recursive https://github.com/jessepollak/card.git
$ cd card
$ git submodule init && git submodule update
$ npm install
$ npm development
Now, if you go to localhost:8080/example in your browser, you should see the demo page.
Places using Card
Card is used in the wild in these places:
Are you using Card in production? If so, we'd love to link to you from this page. Open a PR or drop @jessepollak a line on Twitter and we'll add you right away!
Donations
If you'd like to donate to help support development of Card, send Bitcoin directly to 17NUKd3v7GWben18kGhmFafa4ZpWrXpQSC
or through Coinbase here.