This time I will share jQuery Plugin and tutorial about Create An Interactive Credit Card Form In jQuery – Card.js, hope it will help you in programming stack.
The jQuery Card.js plugin makes it easier to create an interactive credit card form for the payout page of your e-commerce or shopping websites.
Features:
- Card type detection.
- Field validation.
- Input masking.
- Custom placeholders for number, name, expiry, and CVC.
- Also can be implemented in vanilla JavaScript.
See Also:
Installation:
How to use it:
1. Load the core stylesheet card.css
in the head
section of the webpage.
1 |
< link href = "card.css" rel = "stylesheet" > |
2. Load the JavaScript file jquery.card.js
(For jQuery) or card.js
(For Vanilla JavaScript) at the bottom of the webpage
1 |
< script src = "//code.jquery.com/jquery.min.js" ></ script > |
2 |
< script src = "dist/jquery.card.js" ></ script > |
4 |
< script src = "dist/card.js" ></ script > |
3. Create the card wrapper and number/name/expiry/CVC input fields on the webpage.
01 |
< div class = "card-wrapper" ></ div > |
03 |
< div class = "form-container active" > |
05 |
< input type = "text" name = "number" > |
06 |
< input type = "text" name = "first-name" /> |
07 |
< input type = "text" name = "last-name" /> |
08 |
< input type = "text" name = "expiry" /> |
09 |
< input type = "text" name = "cvc" /> |
4. Initialize the Card.js and we’re done.
03 |
ontainer: '.card-wrapper' |
08 |
form: document.querySelector( 'form' ), |
09 |
container: '.card-wrapper' |
5. All possible options to customize the Credit Card Form.
08 |
numberInput: 'input[name="number"]' , |
09 |
expiryInput: 'input[name="expiry"]' , |
10 |
cvcInput: 'input[name="cvc"]' , |
11 |
nameInput: 'input[name="name"]' |
14 |
cardContainer: '.jp-card-container' , |
16 |
numberDisplay: '.jp-card-number' , |
17 |
expiryDisplay: '.jp-card-expiry' , |
18 |
cvcDisplay: '.jp-card-cvc' , |
19 |
nameDisplay: '.jp-card-name' |
24 |
validDate: 'validnthru' , |
25 |
monthYear: 'month/year' |
30 |
number: '•••• •••• •••• ••••' , |
31 |
cvc: '•••' , |
32 |
expiry: '••/••' , |
43 |
valid: 'jp-card-valid' , |
44 |
invalid: 'jp-card-invalid' |
Changelog:
v2.5.2 (2021-04-03)
v2.5.1 (2021-04-01)
- Fix: Update with latest Payment.JS
v2.5.1 (2020-12-05)
- Reflect pre-filled form values in the card preview
v2.5.0 (2020-07-27)
- [Feature]: Adds detection for Maestro, Elo, Troy, Mir, and JCB
- [Fix]: update various dependencies with security issues
2017-08-21