PawelDecowski / jquery-creditcardvalidator

jQuery credit card validation and detection plugin
jquerycreditcardvalidator.com
MIT License
1.06k stars 275 forks source link

why is this not working? #121

Closed NathanielB2 closed 5 years ago

NathanielB2 commented 6 years ago

I can't find any examples on how to get result at the same time only accept certain cards.

I have this code currently but only cards that seem to work is visa and mastercard.

var payment_card_type='';
var classesN = "visa mastercard discover amex";

$('#payment_card_number').validateCreditCard( function(result){ $(this).removeClass(classesN); $(this).addClass( result.card_type.name ); if (result.card_type.name == 'visa') payment_card_type='Visa'; else if (result.card_type.name == 'mastercard') payment_card_type='MasterCard'; else if (result.card_type.name == 'discover') payment_card_type='Discover'; else if (result.card_type.name == 'amex') payment_card_type='Amex'; $('input#payment_card_type').val( payment_card_type ); },{accept: ['visa', 'mastercard', 'discover', 'amex']});

I have also tried and it to does not work for me.

var result = $('#payment_card_number').validateCreditCard({accept: ['visa', 'mastercard', 'discover', 'amex']});

var payment_card_type='';
var classesN = "visa mastercard discover amex";

if (result ){ $('#payment_card_number').removeClass(classesN); $('#payment_card_number').addClass( result.card_type.name ); if (result.card_type.name == 'visa') payment_card_type='Visa'; else if (result.card_type.name == 'mastercard') payment_card_type='MasterCard'; else if (result.card_type.name == 'discover') payment_card_type='Discover'; else if (result.card_type.name == 'amex') payment_card_type='Amex'; $('input#payment_card_type').val( payment_card_type ); }

Can someone please give me an example of .validateCreditCard with the callback and with options ??
.validateCreditCard( [ callback ] [, options ] )

Thanks

PawelDecowski commented 6 years ago

Are you sure you’re testing with valid Discover and Amex cards? Both examples should work as far as I can tell.

NathanielB2 commented 6 years ago

I was using these https://www.paypalobjects.com/en_AU/vhelp/paypalmanager_help/credit_card_numbers.htm

the Discover, MasterCard and Visa test numbers work but not the American Express.

NathanielB2 commented 6 years ago

I think I got it working. But if someone sees anything wrong with how I'm doing this please let me know.

NathanielB2 commented 6 years ago

PawelDecowski I have another question/issue. As I type in a card number say 6011 the added class "valid" is being added to the input box but I have not typed the complete number yet.