Guys,
I need your help with this piece of code, it is a simple way to detect the type of Credit Card entered while is being typed in… You can tell by looking at the First Digit, the First 2 Digits or the First 4 digits of it… Problem is, the logic below is not working as expected. Even if a type a blank space, it gives me “Amex” (!?)
What am I doing wrong!?
Any help will be appreciated,
-Thank you
export function CardNumber_KeyPress()
{
var FirstDigit = parseInt($w(“#CardNumber”).value.substr(0, 1),10);
var TwoDigits = parseInt($w(“#CardNumber”).value.substr(0, 2),10);
var FourDigits = parseInt($w(“#CardNumber”).value.substr(0, 4),10);
if (FirstDigit === 4) {
$w("#text176").text = "Visa" ;}
else if ((TwoDigits > 50 && TwoDigits < 56) || (FourDigits > 2220 && FourDigits < 2721)) {
$w("#text176").text = "Master" ;}
else if ((TwoDigits = 34) || (TwoDigits = 37)) {
$w("#text176").text = "Amex" ;}
else if ((TwoDigits = 64) || (TwoDigits = 65) || (FourDigits = 6011)) {
$w("#text176").text = "Discover" ;}
else {
$w("#text176").text = "Undefined" ;}
}