If you are working on any payment module system on your website and you have to validate user’s credit card information before form submit then in This post I am going to share one useful JavaScript library for building credit card forms, validating inputs, and formatting numbers.Payform is a jQuery-free JavaScript library used to format and validate form inputs related to credit card payments.
Supported card types:
- Visa
- MasterCard
- American Express
- Diners Club
- Discover
- UnionPay
- JCB
- Visa Electron
- Maestro
- Forbrugsforeningen
- Dankort
Libraries
Load Latest jQuery library and the jQuery payform plugin in the document.
<script src="//code.jquery.com/jquery-latest.min.js">script> <script src="dist/jquery.payform.js">script> |
HTML
Create credit card input forms where user will enter their credit card details and this plugin validate credit card details before for submit.
JS
Call the plugin and enable credit card validator.
$('#ccnum').payform('formatCardNumber'); $('#expiry').payform('formatCardExpiry'); $('#cvc').payform('formatCardCVC'); $('#numeric').payform('formatNumeric'); |
See live demo and download source code.
Generate sample credit card from this website (https://creditcardgenerator.in) and Test in Demo Page
This awesome plugin is developed by jondavidjohn. Visit their official github repository for more information and follow for future updates.