Created
October 8, 2017 08:18
-
-
Save kovtunos/4564743ea70ce588c00018fd18e30793 to your computer and use it in GitHub Desktop.
Simple credit card type detection on typing the first digit #jquery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#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