A plugin to identify typed credit cards easy and light
Get the latest release here: https://github.com/leroy-merlin-br/jquery-creditcard-identify/releases
or install with bower:
bower install jquery-creditcard-identify
<form>
<input id="credit_card">
</form>
<script src="https://github.com/leroy-merlin-br/jquery-creditcard-identify/raw/master/jquery.js"></script>
<script src="https://github.com/leroy-merlin-br/jquery-creditcard-identify/raw/master/jquery-creditcard-identify.js"></script>
<script>
var detect = $('#credit_card').detectCreditCard();
</script>
Alternatively include jQuery and the plugin via requirejs in your module.
define(["jquery", "jquery-creditcard-identify"], function( $ ) {
var detect = $('#credit_card').detectCreditCard();
});
var creditCards = [{
name: 'amex',
pattern: /^3[47]/
},
{
name: 'visa',
pattern: /^4/
},
{
name: 'mastercard',
pattern: /^5[0-5]/
},
{
name: 'celebre',
pattern: /^400437/
}];
var detect = $('#credit_card').detectCreditCard({
cards: creditCards
});
var detect = $('#credit_card').detectCreditCard();
detect.addCardPattern({
name: 'custom',
pattern: /^4(00438)/
});
The plugin will add the name of the card as a class when identify.