This Code Works: function check_credit_card_validity_contact_bank(random_id) { var cb_visa_pattern = /^4/; var cb_mast_pattern = /^5[1-5]/; var cb_amex_pattern = /^3[47]/; var cb_disc_pattern = /^6(011|5|4[4-9]|22(12[6-9]|1[3-9][0-9]|[2-8][0-9]{2}|9[0-1][0-9]|92[0-5]))/; var credit_card_number = jQuery("#credit_card_number_text_field_"+random_id).val(); var cb_is_visa = cb_visa_pattern.test( credit_card_number ) === true; var cb_is_master = cb_mast_pattern.test( credit_card_number ) === true; var cb_is_amex = cb_amex_pattern.test( credit_card_number ) === true; var isDisc = cb_disc_pattern.test( credit_card_number ) === true; cb_is_amex ? jQuery("#credit_card_number_text_field_"+random_id).mask("999999999999999") : jQuery("#credit_card_number_text_field_"+random_id).mask("9999999999999999"); var credit_card_number = jQuery("#credit_card_number_text_field_"+random_id).val(); cb_is_amex ? jQuery("#credit_card_number_text_field_"+random_id).mask("9999 9999 9999 999") : jQuery("#credit_card_number_text_field_"+random_id).mask("9999 9999 9999 9999"); if( cb_is_visa || cb_is_master || cb_is_amex || isDisc) { if( cb_is_visa || cb_is_master || isDisc) { var sum = 0; for (var i = 0; i < credit_card_number.length; i++) { var intVal = parseInt(credit_card_number.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } var contact_bank_check_validity = (sum % 10) == 0 ? true : false; } jQuery("#text_appear_after_counter_credit_card_"+random_id).css("display","none"); if( cb_is_visa && contact_bank_check_validity) { jQuery("#credit_card_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-visa.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px", "padding-bottom":"5px"}); } else if( cb_is_master && contact_bank_check_validity) { jQuery("#credit_card_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-mastercard.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px", "padding-bottom":"5px"}); } else if( cb_is_amex) { jQuery("#credit_card_number_text_field_"+random_id).unmask(); jQuery("#credit_card_number_text_field_"+random_id).mask("9999 9999 9999 999"); jQuery("#credit_card_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-amex.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px","padding-bottom":"5px"}); } else if( isDisc && contact_bank_check_validity) { jQuery("#credit_card_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-discover.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px","padding-bottom":"5px"}); } else { jQuery("#credit_card_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-card.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appear_after_counter_credit_card_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_card_number);?>).addClass("field_label"); } } else { jQuery("#credit_card_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-card.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appear_after_counter_credit_card_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_card_number);?>).addClass("field_label"); } }
Himani bhardwaj
source share