Skip to content

Instantly share code, notes, and snippets.

@twalve
Forked from whalec/gist:1015901
Created June 9, 2011 04:24
Show Gist options
  • Save twalve/1016055 to your computer and use it in GitHub Desktop.
Save twalve/1016055 to your computer and use it in GitHub Desktop.
Not tested. Probably doesn't even run. Hacked together jquery plugin. Now plus ninja tip
(function($) {
$.fn.credit_card = function(opts) {
this.opts = opts;
this.change(function(){
var _this = $(this),
val = _this.val(),
twodigit;
_this.parent().children().removeClass("highlighted");
if (val[0] == "4"){
$(opts.visa).addClass("highlighted");
return false;
}
twodigit = val[0] + val[1];
if (twodigit == "34" || twodigit == "37") {
$(opts.amex).addClass("highlighted");
return false;
} else if (twodigit == "51") {
$(opts.mastercard).addClass("highlighted");
return false;
}
})
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment