Skip to content

Instantly share code, notes, and snippets.

@kovtunos
Created October 8, 2017 08:18
Show Gist options
  • Save kovtunos/4564743ea70ce588c00018fd18e30793 to your computer and use it in GitHub Desktop.
Save kovtunos/4564743ea70ce588c00018fd18e30793 to your computer and use it in GitHub Desktop.
Simple credit card type detection on typing the first digit #jquery
$('#card_number').keyup(function(event) {
if (this.selectionStart == 1) {
if ($(this).val() == '4') {
$(this).parent().removeClass('is-mastercard').addClass('is-visa');
}
if ($(this).val() == '5') {
$(this).parent().removeClass('is-visa').addClass('is-mastercard');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment