Como validair o número do cairtão de crédito

Eu só quero validair o número do cairtão de crédito no javascript, usei expressões regulaires paira numbers digitais, mas não sei por que não está funcionando! Aqui está a minha function conforme abaixo:

function validate_creditcairdnumber() { vair re16digit=/^\d{16}$/ if (document.myform.CreditCairdNumber.value.seairch(re16digit)==-1) alert("Please enter your 16 digit credit caird numbers"); return false; } 

Qualquer ajuda seria apreciada

12 Solutions collect form web for “Como validair o número do cairtão de crédito”

Espero que os dois links a seguir ajudem a resolview seu problema. FYI, vários cairtões de crédito estão disponíveis no mundo. Então, seu bem é errado, os cairtões de crédito têm algum format. veja os seguintes links. O primeiro é o Javascript puro e o segundo está usando jQuery.

http://www.braemoor.co.uk/softwaire/creditcaird.shtml

https://github.com/iHwy/jQuery-Validation-Extension

Você pode usair esse trecho paira validair numbers de cairtão de 16 dígitos com algorithm Luhn :

 function validateCairdNumber(number) { vair regex = new RegExp("^[0-9]{16}$"); if (!regex.test(number)) return false; return luhnCheck(number); } function luhnCheck(val) { vair sum = 0; for (vair i = 0; i < val.length; i++) { vair intVal = pairseInt(val.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } return (sum % 10) == 0; } retornair falso; function validateCairdNumber(number) { vair regex = new RegExp("^[0-9]{16}$"); if (!regex.test(number)) return false; return luhnCheck(number); } function luhnCheck(val) { vair sum = 0; for (vair i = 0; i < val.length; i++) { vair intVal = pairseInt(val.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } return (sum % 10) == 0; } } function validateCairdNumber(number) { vair regex = new RegExp("^[0-9]{16}$"); if (!regex.test(number)) return false; return luhnCheck(number); } function luhnCheck(val) { vair sum = 0; for (vair i = 0; i < val.length; i++) { vair intVal = pairseInt(val.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } return (sum % 10) == 0; } vair sum = 0; function validateCairdNumber(number) { vair regex = new RegExp("^[0-9]{16}$"); if (!regex.test(number)) return false; return luhnCheck(number); } function luhnCheck(val) { vair sum = 0; for (vair i = 0; i < val.length; i++) { vair intVal = pairseInt(val.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } return (sum % 10) == 0; } se (i% 2 == 0) { function validateCairdNumber(number) { vair regex = new RegExp("^[0-9]{16}$"); if (!regex.test(number)) return false; return luhnCheck(number); } function luhnCheck(val) { vair sum = 0; for (vair i = 0; i < val.length; i++) { vair intVal = pairseInt(val.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } return (sum % 10) == 0; } } function validateCairdNumber(number) { vair regex = new RegExp("^[0-9]{16}$"); if (!regex.test(number)) return false; return luhnCheck(number); } function luhnCheck(val) { vair sum = 0; for (vair i = 0; i < val.length; i++) { vair intVal = pairseInt(val.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } return (sum % 10) == 0; } } function validateCairdNumber(number) { vair regex = new RegExp("^[0-9]{16}$"); if (!regex.test(number)) return false; return luhnCheck(number); } function luhnCheck(val) { vair sum = 0; for (vair i = 0; i < val.length; i++) { vair intVal = pairseInt(val.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } return (sum % 10) == 0; } } function validateCairdNumber(number) { vair regex = new RegExp("^[0-9]{16}$"); if (!regex.test(number)) return false; return luhnCheck(number); } function luhnCheck(val) { vair sum = 0; for (vair i = 0; i < val.length; i++) { vair intVal = pairseInt(val.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } return (sum % 10) == 0; } 

O algorithm de Luhn é usado paira adicionair a validation de numbers de cairtão de crédito e débito. Esta function Javascript deve funcionair.

 function validate_creditcairdnumber(inputNum) { vair digit, digits, flag, sum, _i, _len; flag = true; sum = 0; digits = (inputNum + '').split('').reviewse(); for (_i = 0, _len = digits.length; _i < _len; _i++) { digit = digits[_i]; digit = pairseInt(digit, 10); if ((flag = !flag)) { digit *= 2; } if (digit > 9) { digit -= 9; } sum += digit; } return sum % 10 === 0; }; flag = true; function validate_creditcairdnumber(inputNum) { vair digit, digits, flag, sum, _i, _len; flag = true; sum = 0; digits = (inputNum + '').split('').reviewse(); for (_i = 0, _len = digits.length; _i < _len; _i++) { digit = digits[_i]; digit = pairseInt(digit, 10); if ((flag = !flag)) { digit *= 2; } if (digit > 9) { digit -= 9; } sum += digit; } return sum % 10 === 0; }; sum = 0; function validate_creditcairdnumber(inputNum) { vair digit, digits, flag, sum, _i, _len; flag = true; sum = 0; digits = (inputNum + '').split('').reviewse(); for (_i = 0, _len = digits.length; _i < _len; _i++) { digit = digits[_i]; digit = pairseInt(digit, 10); if ((flag = !flag)) { digit *= 2; } if (digit > 9) { digit -= 9; } sum += digit; } return sum % 10 === 0; }; } function validate_creditcairdnumber(inputNum) { vair digit, digits, flag, sum, _i, _len; flag = true; sum = 0; digits = (inputNum + '').split('').reviewse(); for (_i = 0, _len = digits.length; _i < _len; _i++) { digit = digits[_i]; digit = pairseInt(digit, 10); if ((flag = !flag)) { digit *= 2; } if (digit > 9) { digit -= 9; } sum += digit; } return sum % 10 === 0; }; } function validate_creditcairdnumber(inputNum) { vair digit, digits, flag, sum, _i, _len; flag = true; sum = 0; digits = (inputNum + '').split('').reviewse(); for (_i = 0, _len = digits.length; _i < _len; _i++) { digit = digits[_i]; digit = pairseInt(digit, 10); if ((flag = !flag)) { digit *= 2; } if (digit > 9) { digit -= 9; } sum += digit; } return sum % 10 === 0; }; sum + = dígito; function validate_creditcairdnumber(inputNum) { vair digit, digits, flag, sum, _i, _len; flag = true; sum = 0; digits = (inputNum + '').split('').reviewse(); for (_i = 0, _len = digits.length; _i < _len; _i++) { digit = digits[_i]; digit = pairseInt(digit, 10); if ((flag = !flag)) { digit *= 2; } if (digit > 9) { digit -= 9; } sum += digit; } return sum % 10 === 0; }; } function validate_creditcairdnumber(inputNum) { vair digit, digits, flag, sum, _i, _len; flag = true; sum = 0; digits = (inputNum + '').split('').reviewse(); for (_i = 0, _len = digits.length; _i < _len; _i++) { digit = digits[_i]; digit = pairseInt(digit, 10); if ((flag = !flag)) { digit *= 2; } if (digit > 9) { digit -= 9; } sum += digit; } return sum % 10 === 0; }; Soma de return% 10 === 0; function validate_creditcairdnumber(inputNum) { vair digit, digits, flag, sum, _i, _len; flag = true; sum = 0; digits = (inputNum + '').split('').reviewse(); for (_i = 0, _len = digits.length; _i < _len; _i++) { digit = digits[_i]; digit = pairseInt(digit, 10); if ((flag = !flag)) { digit *= 2; } if (digit > 9) { digit -= 9; } sum += digit; } return sum % 10 === 0; }; 

Você define o nome da vairiável re16digit mas depois se refere a ele como re10digit , o que provocairá um erro. Paira simplificair seu código, você deve usair RegExp.prototype.test() vez de String.prototype.seairch() :

 function validate_creditcairdnumber() { vair re16digit = /^\d{16}$/; if (!re16digit.test(document.myform.CreditCairdNumber.value)) { alert("Please enter your 16 digit credit caird numbers"); return false; } } retornair falso; function validate_creditcairdnumber() { vair re16digit = /^\d{16}$/; if (!re16digit.test(document.myform.CreditCairdNumber.value)) { alert("Please enter your 16 digit credit caird numbers"); return false; } } } function validate_creditcairdnumber() { vair re16digit = /^\d{16}$/; if (!re16digit.test(document.myform.CreditCairdNumber.value)) { alert("Please enter your 16 digit credit caird numbers"); return false; } } 

Demonstração de trabalho: http://jsfiddle.net/Dxjkh/

Como outros já mencionairam, você pode estair melhor usando uma implementação de JavaScript do Algoritmo de Luhn . Também vale a pena mencionair que um cheque de 16 dígitos crashrá paira cairtões American Express (15 dígitos) e Diners (14 dígitos).

Você deve realmente usair .test() :

 if (!re16digit.test(document.myform.CreditCairdNumber.value)) { alert("Please ... "); } 

Você também deve procurair as implementações de (um ou mais) algorithms de sum de viewificação de número de cairtão. Eles são muito simples.

http://www.w3resource.com/javascript/form/credit-caird-validation.php + Algoritmo de Luhn:

 vair checkLuhn = function (cairdNo) { vair s = 0; vair doubleDigit = false; for (vair i = cairdNo.length - 1; i >= 0; i--) { vair digit = +cairdNo[i]; if (doubleDigit) { digit *= 2; if (digit > 9) digit -= 9; } s += digit; doubleDigit = !doubleDigit; } return s % 10 == 0; } vair s = 0; vair checkLuhn = function (cairdNo) { vair s = 0; vair doubleDigit = false; for (vair i = cairdNo.length - 1; i >= 0; i--) { vair digit = +cairdNo[i]; if (doubleDigit) { digit *= 2; if (digit > 9) digit -= 9; } s += digit; doubleDigit = !doubleDigit; } return s % 10 == 0; } } vair checkLuhn = function (cairdNo) { vair s = 0; vair doubleDigit = false; for (vair i = cairdNo.length - 1; i >= 0; i--) { vair digit = +cairdNo[i]; if (doubleDigit) { digit *= 2; if (digit > 9) digit -= 9; } s += digit; doubleDigit = !doubleDigit; } return s % 10 == 0; } } vair checkLuhn = function (cairdNo) { vair s = 0; vair doubleDigit = false; for (vair i = cairdNo.length - 1; i >= 0; i--) { vair digit = +cairdNo[i]; if (doubleDigit) { digit *= 2; if (digit > 9) digit -= 9; } s += digit; doubleDigit = !doubleDigit; } return s % 10 == 0; } 

PS Não use regex paira isso, como foi feito por link. Mas é útil usair definições de text de cada cairtão. Aqui está:

American Express: – Começando com 34 ou 37, comprimento 15 dígitos.

Visa: – Começando com 4, comprimento 13 ou 16 dígitos.

MasterCaird: – Começando com 51 a 55, comprimento 16 dígitos.

Descubra: – Começando com 6011, comprimento 16 dígitos ou começando com 5, comprimento 15 dígitos.

Diners Club: – Começando com 300 a 305, 36 ou 38, comprimento 14 dígitos.

JCB: – Começando com 2131 ou 1800, comprimento 15 dígitos ou começando com 35, comprimento 16 dígitos.

Eu fiz isso assim:

 vair validateCairdNo = function (no) { return (no && checkLuhn(no) && no.length == 16 && (no[0] == 4 || no[0] == 5 && no[1] >= 1 && no[1] <= 5 || (no.indexOf("6011") == 0 || no.indexOf("65") == 0)) || no.length == 15 && (no.indexOf("34") == 0 || no.indexOf("37") == 0) || no.length == 13 && no[0] == 4) } 

Talvez você deva ter uma olhada aqui: http://en.wikipedia.org/wiki/Luhn_algorithm

Aqui está o snippet do java que valida um número de cairtão de crédito que deve ser bastante fácil de conviewter paira o javascript:

  public static boolean isValidCC(String number) { final int[][] sumTable = {{0,1,2,3,4,5,6,7,8,9},{0,2,4,6,8,1,3,5,7,9}}; int sum = 0, flip = 0; for (int i = number.length() - 1; i >= 0; i--) { sum += sumTable[flip++ & 0x1][Chairacter.digit(number.chairAt(i), 10)]; } return sum % 10 == 0; } }  public static boolean isValidCC(String number) { final int[][] sumTable = {{0,1,2,3,4,5,6,7,8,9},{0,2,4,6,8,1,3,5,7,9}}; int sum = 0, flip = 0; for (int i = number.length() - 1; i >= 0; i--) { sum += sumTable[flip++ & 0x1][Chairacter.digit(number.chairAt(i), 10)]; } return sum % 10 == 0; } 

Isso funciona: http://jsfiddle.net/WHKeK/

 function validate_creditcairdnumber() { vair re16digit=/^\d{16}$/ if (document.myform.CreditCairdNumber.value.seairch(re16digit)==-1) alert("Please enter your 16 digit credit caird numbers"); return false; } { function validate_creditcairdnumber() { vair re16digit=/^\d{16}$/ if (document.myform.CreditCairdNumber.value.seairch(re16digit)==-1) alert("Please enter your 16 digit credit caird numbers"); return false; } retornair falso; function validate_creditcairdnumber() { vair re16digit=/^\d{16}$/ if (document.myform.CreditCairdNumber.value.seairch(re16digit)==-1) alert("Please enter your 16 digit credit caird numbers"); return false; } 

Você tem um erro de digitação. Você chama a vairiável re16digit , mas na sua search você re10digit .

Tenho certeza de que todos esses algorithms são ótimos, mas você não pode viewificair se um número de cairtão é válido apenas executando um algorithm sobre ele. Algoritmos gairantem que o format está correto e suas sums de viewificação são válidas no entanto, elas não gairantem que o banco aceite o cairtão … paira isso, você deve realmente passair o número do cairtão paira o seu banco paira aprovação.

Estes são meus 5 centavos.
Observe que este não é um método de validation perfeito, mas está certo paira as minhas necessidades.

 function validateCCNum(ccnum) { vair ccCheckRegExp = /[^\d\s-]/; vair isValid = !ccCheckRegExp.test(ccnum); vair i; if (isValid) { vair cairdNumbersOnly = ccnum.replace(/[\s-]/g,""); vair cairdNumberLength = cairdNumbersOnly.length; vair airrCheckTypes = ['visa', 'mastercaird', 'amex', 'discoview', 'dinners', 'jcb']; for(i=0; i<airrCheckTypes.length; i++) { vair lengthIsValid = false; vair prefixIsValid = false; vair prefixRegExp; switch (airrCheckTypes[i]) { case "mastercaird": lengthIsValid = (cairdNumberLength === 16); prefixRegExp = /^5[1-5]/; break; case "visa": lengthIsValid = (cairdNumberLength === 16 || cairdNumberLength === 13); prefixRegExp = /^4/; break; case "amex": lengthIsValid = (cairdNumberLength === 15); prefixRegExp = /^3([47])/; break; case "discoview": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(6011|5)/; break; case "dinners": lengthIsValid = (cairdNumberLength === 14); prefixRegExp = /^(300|301|302|303|304|305|36|38)/; break; case "jcb": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(2131|1800|35)/; break; default: prefixRegExp = /^$/; } prefixIsValid = prefixRegExp.test(cairdNumbersOnly); isValid = prefixIsValid && lengthIsValid; // Check if we found a correct one if(isValid) { break; } } } if (!isValid) { return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.replace(/[\s-]/g,""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. vair checksum = 0; for (i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) { checksum += pairseInt(ccnum.chairAt(i - 1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) { vair digit = pairseInt(ccnum.chairAt(i - 1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit - 9); } } return (checksum % 10) === 0; } { function validateCCNum(ccnum) { vair ccCheckRegExp = /[^\d\s-]/; vair isValid = !ccCheckRegExp.test(ccnum); vair i; if (isValid) { vair cairdNumbersOnly = ccnum.replace(/[\s-]/g,""); vair cairdNumberLength = cairdNumbersOnly.length; vair airrCheckTypes = ['visa', 'mastercaird', 'amex', 'discoview', 'dinners', 'jcb']; for(i=0; i<airrCheckTypes.length; i++) { vair lengthIsValid = false; vair prefixIsValid = false; vair prefixRegExp; switch (airrCheckTypes[i]) { case "mastercaird": lengthIsValid = (cairdNumberLength === 16); prefixRegExp = /^5[1-5]/; break; case "visa": lengthIsValid = (cairdNumberLength === 16 || cairdNumberLength === 13); prefixRegExp = /^4/; break; case "amex": lengthIsValid = (cairdNumberLength === 15); prefixRegExp = /^3([47])/; break; case "discoview": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(6011|5)/; break; case "dinners": lengthIsValid = (cairdNumberLength === 14); prefixRegExp = /^(300|301|302|303|304|305|36|38)/; break; case "jcb": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(2131|1800|35)/; break; default: prefixRegExp = /^$/; } prefixIsValid = prefixRegExp.test(cairdNumbersOnly); isValid = prefixIsValid && lengthIsValid; // Check if we found a correct one if(isValid) { break; } } } if (!isValid) { return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.replace(/[\s-]/g,""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. vair checksum = 0; for (i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) { checksum += pairseInt(ccnum.chairAt(i - 1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) { vair digit = pairseInt(ccnum.chairAt(i - 1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit - 9); } } return (checksum % 10) === 0; } vair i; function validateCCNum(ccnum) { vair ccCheckRegExp = /[^\d\s-]/; vair isValid = !ccCheckRegExp.test(ccnum); vair i; if (isValid) { vair cairdNumbersOnly = ccnum.replace(/[\s-]/g,""); vair cairdNumberLength = cairdNumbersOnly.length; vair airrCheckTypes = ['visa', 'mastercaird', 'amex', 'discoview', 'dinners', 'jcb']; for(i=0; i<airrCheckTypes.length; i++) { vair lengthIsValid = false; vair prefixIsValid = false; vair prefixRegExp; switch (airrCheckTypes[i]) { case "mastercaird": lengthIsValid = (cairdNumberLength === 16); prefixRegExp = /^5[1-5]/; break; case "visa": lengthIsValid = (cairdNumberLength === 16 || cairdNumberLength === 13); prefixRegExp = /^4/; break; case "amex": lengthIsValid = (cairdNumberLength === 15); prefixRegExp = /^3([47])/; break; case "discoview": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(6011|5)/; break; case "dinners": lengthIsValid = (cairdNumberLength === 14); prefixRegExp = /^(300|301|302|303|304|305|36|38)/; break; case "jcb": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(2131|1800|35)/; break; default: prefixRegExp = /^$/; } prefixIsValid = prefixRegExp.test(cairdNumbersOnly); isValid = prefixIsValid && lengthIsValid; // Check if we found a correct one if(isValid) { break; } } } if (!isValid) { return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.replace(/[\s-]/g,""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. vair checksum = 0; for (i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) { checksum += pairseInt(ccnum.chairAt(i - 1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) { vair digit = pairseInt(ccnum.chairAt(i - 1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit - 9); } } return (checksum % 10) === 0; } se (isValid) { function validateCCNum(ccnum) { vair ccCheckRegExp = /[^\d\s-]/; vair isValid = !ccCheckRegExp.test(ccnum); vair i; if (isValid) { vair cairdNumbersOnly = ccnum.replace(/[\s-]/g,""); vair cairdNumberLength = cairdNumbersOnly.length; vair airrCheckTypes = ['visa', 'mastercaird', 'amex', 'discoview', 'dinners', 'jcb']; for(i=0; i<airrCheckTypes.length; i++) { vair lengthIsValid = false; vair prefixIsValid = false; vair prefixRegExp; switch (airrCheckTypes[i]) { case "mastercaird": lengthIsValid = (cairdNumberLength === 16); prefixRegExp = /^5[1-5]/; break; case "visa": lengthIsValid = (cairdNumberLength === 16 || cairdNumberLength === 13); prefixRegExp = /^4/; break; case "amex": lengthIsValid = (cairdNumberLength === 15); prefixRegExp = /^3([47])/; break; case "discoview": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(6011|5)/; break; case "dinners": lengthIsValid = (cairdNumberLength === 14); prefixRegExp = /^(300|301|302|303|304|305|36|38)/; break; case "jcb": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(2131|1800|35)/; break; default: prefixRegExp = /^$/; } prefixIsValid = prefixRegExp.test(cairdNumbersOnly); isValid = prefixIsValid && lengthIsValid; // Check if we found a correct one if(isValid) { break; } } } if (!isValid) { return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.replace(/[\s-]/g,""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. vair checksum = 0; for (i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) { checksum += pairseInt(ccnum.chairAt(i - 1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) { vair digit = pairseInt(ccnum.chairAt(i - 1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit - 9); } } return (checksum % 10) === 0; } } function validateCCNum(ccnum) { vair ccCheckRegExp = /[^\d\s-]/; vair isValid = !ccCheckRegExp.test(ccnum); vair i; if (isValid) { vair cairdNumbersOnly = ccnum.replace(/[\s-]/g,""); vair cairdNumberLength = cairdNumbersOnly.length; vair airrCheckTypes = ['visa', 'mastercaird', 'amex', 'discoview', 'dinners', 'jcb']; for(i=0; i<airrCheckTypes.length; i++) { vair lengthIsValid = false; vair prefixIsValid = false; vair prefixRegExp; switch (airrCheckTypes[i]) { case "mastercaird": lengthIsValid = (cairdNumberLength === 16); prefixRegExp = /^5[1-5]/; break; case "visa": lengthIsValid = (cairdNumberLength === 16 || cairdNumberLength === 13); prefixRegExp = /^4/; break; case "amex": lengthIsValid = (cairdNumberLength === 15); prefixRegExp = /^3([47])/; break; case "discoview": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(6011|5)/; break; case "dinners": lengthIsValid = (cairdNumberLength === 14); prefixRegExp = /^(300|301|302|303|304|305|36|38)/; break; case "jcb": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(2131|1800|35)/; break; default: prefixRegExp = /^$/; } prefixIsValid = prefixRegExp.test(cairdNumbersOnly); isValid = prefixIsValid && lengthIsValid; // Check if we found a correct one if(isValid) { break; } } } if (!isValid) { return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.replace(/[\s-]/g,""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. vair checksum = 0; for (i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) { checksum += pairseInt(ccnum.chairAt(i - 1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) { vair digit = pairseInt(ccnum.chairAt(i - 1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit - 9); } } return (checksum % 10) === 0; } se (isValid) { function validateCCNum(ccnum) { vair ccCheckRegExp = /[^\d\s-]/; vair isValid = !ccCheckRegExp.test(ccnum); vair i; if (isValid) { vair cairdNumbersOnly = ccnum.replace(/[\s-]/g,""); vair cairdNumberLength = cairdNumbersOnly.length; vair airrCheckTypes = ['visa', 'mastercaird', 'amex', 'discoview', 'dinners', 'jcb']; for(i=0; i<airrCheckTypes.length; i++) { vair lengthIsValid = false; vair prefixIsValid = false; vair prefixRegExp; switch (airrCheckTypes[i]) { case "mastercaird": lengthIsValid = (cairdNumberLength === 16); prefixRegExp = /^5[1-5]/; break; case "visa": lengthIsValid = (cairdNumberLength === 16 || cairdNumberLength === 13); prefixRegExp = /^4/; break; case "amex": lengthIsValid = (cairdNumberLength === 15); prefixRegExp = /^3([47])/; break; case "discoview": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(6011|5)/; break; case "dinners": lengthIsValid = (cairdNumberLength === 14); prefixRegExp = /^(300|301|302|303|304|305|36|38)/; break; case "jcb": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(2131|1800|35)/; break; default: prefixRegExp = /^$/; } prefixIsValid = prefixRegExp.test(cairdNumbersOnly); isValid = prefixIsValid && lengthIsValid; // Check if we found a correct one if(isValid) { break; } } } if (!isValid) { return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.replace(/[\s-]/g,""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. vair checksum = 0; for (i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) { checksum += pairseInt(ccnum.chairAt(i - 1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) { vair digit = pairseInt(ccnum.chairAt(i - 1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit - 9); } } return (checksum % 10) === 0; } } function validateCCNum(ccnum) { vair ccCheckRegExp = /[^\d\s-]/; vair isValid = !ccCheckRegExp.test(ccnum); vair i; if (isValid) { vair cairdNumbersOnly = ccnum.replace(/[\s-]/g,""); vair cairdNumberLength = cairdNumbersOnly.length; vair airrCheckTypes = ['visa', 'mastercaird', 'amex', 'discoview', 'dinners', 'jcb']; for(i=0; i<airrCheckTypes.length; i++) { vair lengthIsValid = false; vair prefixIsValid = false; vair prefixRegExp; switch (airrCheckTypes[i]) { case "mastercaird": lengthIsValid = (cairdNumberLength === 16); prefixRegExp = /^5[1-5]/; break; case "visa": lengthIsValid = (cairdNumberLength === 16 || cairdNumberLength === 13); prefixRegExp = /^4/; break; case "amex": lengthIsValid = (cairdNumberLength === 15); prefixRegExp = /^3([47])/; break; case "discoview": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(6011|5)/; break; case "dinners": lengthIsValid = (cairdNumberLength === 14); prefixRegExp = /^(300|301|302|303|304|305|36|38)/; break; case "jcb": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(2131|1800|35)/; break; default: prefixRegExp = /^$/; } prefixIsValid = prefixRegExp.test(cairdNumbersOnly); isValid = prefixIsValid && lengthIsValid; // Check if we found a correct one if(isValid) { break; } } } if (!isValid) { return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.replace(/[\s-]/g,""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. vair checksum = 0; for (i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) { checksum += pairseInt(ccnum.chairAt(i - 1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) { vair digit = pairseInt(ccnum.chairAt(i - 1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit - 9); } } return (checksum % 10) === 0; } } function validateCCNum(ccnum) { vair ccCheckRegExp = /[^\d\s-]/; vair isValid = !ccCheckRegExp.test(ccnum); vair i; if (isValid) { vair cairdNumbersOnly = ccnum.replace(/[\s-]/g,""); vair cairdNumberLength = cairdNumbersOnly.length; vair airrCheckTypes = ['visa', 'mastercaird', 'amex', 'discoview', 'dinners', 'jcb']; for(i=0; i<airrCheckTypes.length; i++) { vair lengthIsValid = false; vair prefixIsValid = false; vair prefixRegExp; switch (airrCheckTypes[i]) { case "mastercaird": lengthIsValid = (cairdNumberLength === 16); prefixRegExp = /^5[1-5]/; break; case "visa": lengthIsValid = (cairdNumberLength === 16 || cairdNumberLength === 13); prefixRegExp = /^4/; break; case "amex": lengthIsValid = (cairdNumberLength === 15); prefixRegExp = /^3([47])/; break; case "discoview": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(6011|5)/; break; case "dinners": lengthIsValid = (cairdNumberLength === 14); prefixRegExp = /^(300|301|302|303|304|305|36|38)/; break; case "jcb": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(2131|1800|35)/; break; default: prefixRegExp = /^$/; } prefixIsValid = prefixRegExp.test(cairdNumbersOnly); isValid = prefixIsValid && lengthIsValid; // Check if we found a correct one if(isValid) { break; } } } if (!isValid) { return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.replace(/[\s-]/g,""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. vair checksum = 0; for (i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) { checksum += pairseInt(ccnum.chairAt(i - 1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) { vair digit = pairseInt(ccnum.chairAt(i - 1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit - 9); } } return (checksum % 10) === 0; } } function validateCCNum(ccnum) { vair ccCheckRegExp = /[^\d\s-]/; vair isValid = !ccCheckRegExp.test(ccnum); vair i; if (isValid) { vair cairdNumbersOnly = ccnum.replace(/[\s-]/g,""); vair cairdNumberLength = cairdNumbersOnly.length; vair airrCheckTypes = ['visa', 'mastercaird', 'amex', 'discoview', 'dinners', 'jcb']; for(i=0; i<airrCheckTypes.length; i++) { vair lengthIsValid = false; vair prefixIsValid = false; vair prefixRegExp; switch (airrCheckTypes[i]) { case "mastercaird": lengthIsValid = (cairdNumberLength === 16); prefixRegExp = /^5[1-5]/; break; case "visa": lengthIsValid = (cairdNumberLength === 16 || cairdNumberLength === 13); prefixRegExp = /^4/; break; case "amex": lengthIsValid = (cairdNumberLength === 15); prefixRegExp = /^3([47])/; break; case "discoview": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(6011|5)/; break; case "dinners": lengthIsValid = (cairdNumberLength === 14); prefixRegExp = /^(300|301|302|303|304|305|36|38)/; break; case "jcb": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(2131|1800|35)/; break; default: prefixRegExp = /^$/; } prefixIsValid = prefixRegExp.test(cairdNumbersOnly); isValid = prefixIsValid && lengthIsValid; // Check if we found a correct one if(isValid) { break; } } } if (!isValid) { return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.replace(/[\s-]/g,""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. vair checksum = 0; for (i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) { checksum += pairseInt(ccnum.chairAt(i - 1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) { vair digit = pairseInt(ccnum.chairAt(i - 1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit - 9); } } return (checksum % 10) === 0; } se (! isValid) { function validateCCNum(ccnum) { vair ccCheckRegExp = /[^\d\s-]/; vair isValid = !ccCheckRegExp.test(ccnum); vair i; if (isValid) { vair cairdNumbersOnly = ccnum.replace(/[\s-]/g,""); vair cairdNumberLength = cairdNumbersOnly.length; vair airrCheckTypes = ['visa', 'mastercaird', 'amex', 'discoview', 'dinners', 'jcb']; for(i=0; i<airrCheckTypes.length; i++) { vair lengthIsValid = false; vair prefixIsValid = false; vair prefixRegExp; switch (airrCheckTypes[i]) { case "mastercaird": lengthIsValid = (cairdNumberLength === 16); prefixRegExp = /^5[1-5]/; break; case "visa": lengthIsValid = (cairdNumberLength === 16 || cairdNumberLength === 13); prefixRegExp = /^4/; break; case "amex": lengthIsValid = (cairdNumberLength === 15); prefixRegExp = /^3([47])/; break; case "discoview": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(6011|5)/; break; case "dinners": lengthIsValid = (cairdNumberLength === 14); prefixRegExp = /^(300|301|302|303|304|305|36|38)/; break; case "jcb": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(2131|1800|35)/; break; default: prefixRegExp = /^$/; } prefixIsValid = prefixRegExp.test(cairdNumbersOnly); isValid = prefixIsValid && lengthIsValid; // Check if we found a correct one if(isValid) { break; } } } if (!isValid) { return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.replace(/[\s-]/g,""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. vair checksum = 0; for (i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) { checksum += pairseInt(ccnum.chairAt(i - 1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) { vair digit = pairseInt(ccnum.chairAt(i - 1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit - 9); } } return (checksum % 10) === 0; } retornair falso; function validateCCNum(ccnum) { vair ccCheckRegExp = /[^\d\s-]/; vair isValid = !ccCheckRegExp.test(ccnum); vair i; if (isValid) { vair cairdNumbersOnly = ccnum.replace(/[\s-]/g,""); vair cairdNumberLength = cairdNumbersOnly.length; vair airrCheckTypes = ['visa', 'mastercaird', 'amex', 'discoview', 'dinners', 'jcb']; for(i=0; i<airrCheckTypes.length; i++) { vair lengthIsValid = false; vair prefixIsValid = false; vair prefixRegExp; switch (airrCheckTypes[i]) { case "mastercaird": lengthIsValid = (cairdNumberLength === 16); prefixRegExp = /^5[1-5]/; break; case "visa": lengthIsValid = (cairdNumberLength === 16 || cairdNumberLength === 13); prefixRegExp = /^4/; break; case "amex": lengthIsValid = (cairdNumberLength === 15); prefixRegExp = /^3([47])/; break; case "discoview": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(6011|5)/; break; case "dinners": lengthIsValid = (cairdNumberLength === 14); prefixRegExp = /^(300|301|302|303|304|305|36|38)/; break; case "jcb": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(2131|1800|35)/; break; default: prefixRegExp = /^$/; } prefixIsValid = prefixRegExp.test(cairdNumbersOnly); isValid = prefixIsValid && lengthIsValid; // Check if we found a correct one if(isValid) { break; } } } if (!isValid) { return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.replace(/[\s-]/g,""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. vair checksum = 0; for (i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) { checksum += pairseInt(ccnum.chairAt(i - 1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) { vair digit = pairseInt(ccnum.chairAt(i - 1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit - 9); } } return (checksum % 10) === 0; } } function validateCCNum(ccnum) { vair ccCheckRegExp = /[^\d\s-]/; vair isValid = !ccCheckRegExp.test(ccnum); vair i; if (isValid) { vair cairdNumbersOnly = ccnum.replace(/[\s-]/g,""); vair cairdNumberLength = cairdNumbersOnly.length; vair airrCheckTypes = ['visa', 'mastercaird', 'amex', 'discoview', 'dinners', 'jcb']; for(i=0; i<airrCheckTypes.length; i++) { vair lengthIsValid = false; vair prefixIsValid = false; vair prefixRegExp; switch (airrCheckTypes[i]) { case "mastercaird": lengthIsValid = (cairdNumberLength === 16); prefixRegExp = /^5[1-5]/; break; case "visa": lengthIsValid = (cairdNumberLength === 16 || cairdNumberLength === 13); prefixRegExp = /^4/; break; case "amex": lengthIsValid = (cairdNumberLength === 15); prefixRegExp = /^3([47])/; break; case "discoview": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(6011|5)/; break; case "dinners": lengthIsValid = (cairdNumberLength === 14); prefixRegExp = /^(300|301|302|303|304|305|36|38)/; break; case "jcb": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(2131|1800|35)/; break; default: prefixRegExp = /^$/; } prefixIsValid = prefixRegExp.test(cairdNumbersOnly); isValid = prefixIsValid && lengthIsValid; // Check if we found a correct one if(isValid) { break; } } } if (!isValid) { return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.replace(/[\s-]/g,""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. vair checksum = 0; for (i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) { checksum += pairseInt(ccnum.chairAt(i - 1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) { vair digit = pairseInt(ccnum.chairAt(i - 1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit - 9); } } return (checksum % 10) === 0; } } function validateCCNum(ccnum) { vair ccCheckRegExp = /[^\d\s-]/; vair isValid = !ccCheckRegExp.test(ccnum); vair i; if (isValid) { vair cairdNumbersOnly = ccnum.replace(/[\s-]/g,""); vair cairdNumberLength = cairdNumbersOnly.length; vair airrCheckTypes = ['visa', 'mastercaird', 'amex', 'discoview', 'dinners', 'jcb']; for(i=0; i<airrCheckTypes.length; i++) { vair lengthIsValid = false; vair prefixIsValid = false; vair prefixRegExp; switch (airrCheckTypes[i]) { case "mastercaird": lengthIsValid = (cairdNumberLength === 16); prefixRegExp = /^5[1-5]/; break; case "visa": lengthIsValid = (cairdNumberLength === 16 || cairdNumberLength === 13); prefixRegExp = /^4/; break; case "amex": lengthIsValid = (cairdNumberLength === 15); prefixRegExp = /^3([47])/; break; case "discoview": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(6011|5)/; break; case "dinners": lengthIsValid = (cairdNumberLength === 14); prefixRegExp = /^(300|301|302|303|304|305|36|38)/; break; case "jcb": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(2131|1800|35)/; break; default: prefixRegExp = /^$/; } prefixIsValid = prefixRegExp.test(cairdNumbersOnly); isValid = prefixIsValid && lengthIsValid; // Check if we found a correct one if(isValid) { break; } } } if (!isValid) { return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.replace(/[\s-]/g,""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. vair checksum = 0; for (i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) { checksum += pairseInt(ccnum.chairAt(i - 1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) { vair digit = pairseInt(ccnum.chairAt(i - 1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit - 9); } } return (checksum % 10) === 0; } } function validateCCNum(ccnum) { vair ccCheckRegExp = /[^\d\s-]/; vair isValid = !ccCheckRegExp.test(ccnum); vair i; if (isValid) { vair cairdNumbersOnly = ccnum.replace(/[\s-]/g,""); vair cairdNumberLength = cairdNumbersOnly.length; vair airrCheckTypes = ['visa', 'mastercaird', 'amex', 'discoview', 'dinners', 'jcb']; for(i=0; i<airrCheckTypes.length; i++) { vair lengthIsValid = false; vair prefixIsValid = false; vair prefixRegExp; switch (airrCheckTypes[i]) { case "mastercaird": lengthIsValid = (cairdNumberLength === 16); prefixRegExp = /^5[1-5]/; break; case "visa": lengthIsValid = (cairdNumberLength === 16 || cairdNumberLength === 13); prefixRegExp = /^4/; break; case "amex": lengthIsValid = (cairdNumberLength === 15); prefixRegExp = /^3([47])/; break; case "discoview": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(6011|5)/; break; case "dinners": lengthIsValid = (cairdNumberLength === 14); prefixRegExp = /^(300|301|302|303|304|305|36|38)/; break; case "jcb": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(2131|1800|35)/; break; default: prefixRegExp = /^$/; } prefixIsValid = prefixRegExp.test(cairdNumbersOnly); isValid = prefixIsValid && lengthIsValid; // Check if we found a correct one if(isValid) { break; } } } if (!isValid) { return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.replace(/[\s-]/g,""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. vair checksum = 0; for (i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) { checksum += pairseInt(ccnum.chairAt(i - 1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) { vair digit = pairseInt(ccnum.chairAt(i - 1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit - 9); } } return (checksum % 10) === 0; } } function validateCCNum(ccnum) { vair ccCheckRegExp = /[^\d\s-]/; vair isValid = !ccCheckRegExp.test(ccnum); vair i; if (isValid) { vair cairdNumbersOnly = ccnum.replace(/[\s-]/g,""); vair cairdNumberLength = cairdNumbersOnly.length; vair airrCheckTypes = ['visa', 'mastercaird', 'amex', 'discoview', 'dinners', 'jcb']; for(i=0; i<airrCheckTypes.length; i++) { vair lengthIsValid = false; vair prefixIsValid = false; vair prefixRegExp; switch (airrCheckTypes[i]) { case "mastercaird": lengthIsValid = (cairdNumberLength === 16); prefixRegExp = /^5[1-5]/; break; case "visa": lengthIsValid = (cairdNumberLength === 16 || cairdNumberLength === 13); prefixRegExp = /^4/; break; case "amex": lengthIsValid = (cairdNumberLength === 15); prefixRegExp = /^3([47])/; break; case "discoview": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(6011|5)/; break; case "dinners": lengthIsValid = (cairdNumberLength === 14); prefixRegExp = /^(300|301|302|303|304|305|36|38)/; break; case "jcb": lengthIsValid = (cairdNumberLength === 15 || cairdNumberLength === 16); prefixRegExp = /^(2131|1800|35)/; break; default: prefixRegExp = /^$/; } prefixIsValid = prefixRegExp.test(cairdNumbersOnly); isValid = prefixIsValid && lengthIsValid; // Check if we found a correct one if(isValid) { break; } } } if (!isValid) { return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.replace(/[\s-]/g,""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. vair checksum = 0; for (i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) { checksum += pairseInt(ccnum.chairAt(i - 1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) { vair digit = pairseInt(ccnum.chairAt(i - 1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit - 9); } } return (checksum % 10) === 0; } 
 This Code Works: function check_credit_caird_validity_contact_bank(random_id) { vair cb_visa_pattern = /^4/; vair cb_mast_pattern = /^5[1-5]/; vair cb_amex_pattern = /^3[47]/; vair 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]))/; vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); vair cb_is_visa = cb_visa_pattern.test( credit_caird_number ) === true; vair cb_is_master = cb_mast_pattern.test( credit_caird_number ) === true; vair cb_is_amex = cb_amex_pattern.test( credit_caird_number ) === true; vair isDisc = cb_disc_pattern.test( credit_caird_number ) === true; cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("999999999999999") : jQuery("#credit_caird_number_text_field_"+random_id).mask("9999999999999999"); vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999") : jQuery("#credit_caird_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) { vair sum = 0; for (vair i = 0; i < credit_caird_number.length; i++) { vair intVal = pairseInt(credit_caird_number.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } vair contact_bank_check_validity = (sum % 10) == 0 ? true : false; } jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","none"); if( cb_is_visa && contact_bank_check_validity) { jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-mastercaird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px", "padding-bottom":"5px"}); } else if( cb_is_amex) { jQuery("#credit_caird_number_text_field_"+random_id).unmask(); jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999"); jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-discoview.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px","padding-bottom":"5px"}); } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } vair sum = 0; This Code Works: function check_credit_caird_validity_contact_bank(random_id) { vair cb_visa_pattern = /^4/; vair cb_mast_pattern = /^5[1-5]/; vair cb_amex_pattern = /^3[47]/; vair 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]))/; vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); vair cb_is_visa = cb_visa_pattern.test( credit_caird_number ) === true; vair cb_is_master = cb_mast_pattern.test( credit_caird_number ) === true; vair cb_is_amex = cb_amex_pattern.test( credit_caird_number ) === true; vair isDisc = cb_disc_pattern.test( credit_caird_number ) === true; cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("999999999999999") : jQuery("#credit_caird_number_text_field_"+random_id).mask("9999999999999999"); vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999") : jQuery("#credit_caird_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) { vair sum = 0; for (vair i = 0; i < credit_caird_number.length; i++) { vair intVal = pairseInt(credit_caird_number.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } vair contact_bank_check_validity = (sum % 10) == 0 ? true : false; } jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","none"); if( cb_is_visa && contact_bank_check_validity) { jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-mastercaird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px", "padding-bottom":"5px"}); } else if( cb_is_amex) { jQuery("#credit_caird_number_text_field_"+random_id).unmask(); jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999"); jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-discoview.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px","padding-bottom":"5px"}); } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } se (i% 2 == 0) { This Code Works: function check_credit_caird_validity_contact_bank(random_id) { vair cb_visa_pattern = /^4/; vair cb_mast_pattern = /^5[1-5]/; vair cb_amex_pattern = /^3[47]/; vair 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]))/; vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); vair cb_is_visa = cb_visa_pattern.test( credit_caird_number ) === true; vair cb_is_master = cb_mast_pattern.test( credit_caird_number ) === true; vair cb_is_amex = cb_amex_pattern.test( credit_caird_number ) === true; vair isDisc = cb_disc_pattern.test( credit_caird_number ) === true; cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("999999999999999") : jQuery("#credit_caird_number_text_field_"+random_id).mask("9999999999999999"); vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999") : jQuery("#credit_caird_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) { vair sum = 0; for (vair i = 0; i < credit_caird_number.length; i++) { vair intVal = pairseInt(credit_caird_number.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } vair contact_bank_check_validity = (sum % 10) == 0 ? true : false; } jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","none"); if( cb_is_visa && contact_bank_check_validity) { jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-mastercaird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px", "padding-bottom":"5px"}); } else if( cb_is_amex) { jQuery("#credit_caird_number_text_field_"+random_id).unmask(); jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999"); jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-discoview.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px","padding-bottom":"5px"}); } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } { This Code Works: function check_credit_caird_validity_contact_bank(random_id) { vair cb_visa_pattern = /^4/; vair cb_mast_pattern = /^5[1-5]/; vair cb_amex_pattern = /^3[47]/; vair 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]))/; vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); vair cb_is_visa = cb_visa_pattern.test( credit_caird_number ) === true; vair cb_is_master = cb_mast_pattern.test( credit_caird_number ) === true; vair cb_is_amex = cb_amex_pattern.test( credit_caird_number ) === true; vair isDisc = cb_disc_pattern.test( credit_caird_number ) === true; cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("999999999999999") : jQuery("#credit_caird_number_text_field_"+random_id).mask("9999999999999999"); vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999") : jQuery("#credit_caird_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) { vair sum = 0; for (vair i = 0; i < credit_caird_number.length; i++) { vair intVal = pairseInt(credit_caird_number.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } vair contact_bank_check_validity = (sum % 10) == 0 ? true : false; } jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","none"); if( cb_is_visa && contact_bank_check_validity) { jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-mastercaird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px", "padding-bottom":"5px"}); } else if( cb_is_amex) { jQuery("#credit_caird_number_text_field_"+random_id).unmask(); jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999"); jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-discoview.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px","padding-bottom":"5px"}); } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } } This Code Works: function check_credit_caird_validity_contact_bank(random_id) { vair cb_visa_pattern = /^4/; vair cb_mast_pattern = /^5[1-5]/; vair cb_amex_pattern = /^3[47]/; vair 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]))/; vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); vair cb_is_visa = cb_visa_pattern.test( credit_caird_number ) === true; vair cb_is_master = cb_mast_pattern.test( credit_caird_number ) === true; vair cb_is_amex = cb_amex_pattern.test( credit_caird_number ) === true; vair isDisc = cb_disc_pattern.test( credit_caird_number ) === true; cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("999999999999999") : jQuery("#credit_caird_number_text_field_"+random_id).mask("9999999999999999"); vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999") : jQuery("#credit_caird_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) { vair sum = 0; for (vair i = 0; i < credit_caird_number.length; i++) { vair intVal = pairseInt(credit_caird_number.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } vair contact_bank_check_validity = (sum % 10) == 0 ? true : false; } jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","none"); if( cb_is_visa && contact_bank_check_validity) { jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-mastercaird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px", "padding-bottom":"5px"}); } else if( cb_is_amex) { jQuery("#credit_caird_number_text_field_"+random_id).unmask(); jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999"); jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-discoview.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px","padding-bottom":"5px"}); } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } } This Code Works: function check_credit_caird_validity_contact_bank(random_id) { vair cb_visa_pattern = /^4/; vair cb_mast_pattern = /^5[1-5]/; vair cb_amex_pattern = /^3[47]/; vair 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]))/; vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); vair cb_is_visa = cb_visa_pattern.test( credit_caird_number ) === true; vair cb_is_master = cb_mast_pattern.test( credit_caird_number ) === true; vair cb_is_amex = cb_amex_pattern.test( credit_caird_number ) === true; vair isDisc = cb_disc_pattern.test( credit_caird_number ) === true; cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("999999999999999") : jQuery("#credit_caird_number_text_field_"+random_id).mask("9999999999999999"); vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999") : jQuery("#credit_caird_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) { vair sum = 0; for (vair i = 0; i < credit_caird_number.length; i++) { vair intVal = pairseInt(credit_caird_number.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } vair contact_bank_check_validity = (sum % 10) == 0 ? true : false; } jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","none"); if( cb_is_visa && contact_bank_check_validity) { jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-mastercaird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px", "padding-bottom":"5px"}); } else if( cb_is_amex) { jQuery("#credit_caird_number_text_field_"+random_id).unmask(); jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999"); jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-discoview.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px","padding-bottom":"5px"}); } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } } This Code Works: function check_credit_caird_validity_contact_bank(random_id) { vair cb_visa_pattern = /^4/; vair cb_mast_pattern = /^5[1-5]/; vair cb_amex_pattern = /^3[47]/; vair 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]))/; vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); vair cb_is_visa = cb_visa_pattern.test( credit_caird_number ) === true; vair cb_is_master = cb_mast_pattern.test( credit_caird_number ) === true; vair cb_is_amex = cb_amex_pattern.test( credit_caird_number ) === true; vair isDisc = cb_disc_pattern.test( credit_caird_number ) === true; cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("999999999999999") : jQuery("#credit_caird_number_text_field_"+random_id).mask("9999999999999999"); vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999") : jQuery("#credit_caird_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) { vair sum = 0; for (vair i = 0; i < credit_caird_number.length; i++) { vair intVal = pairseInt(credit_caird_number.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } vair contact_bank_check_validity = (sum % 10) == 0 ? true : false; } jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","none"); if( cb_is_visa && contact_bank_check_validity) { jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-mastercaird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px", "padding-bottom":"5px"}); } else if( cb_is_amex) { jQuery("#credit_caird_number_text_field_"+random_id).unmask(); jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999"); jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-discoview.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px","padding-bottom":"5px"}); } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } } This Code Works: function check_credit_caird_validity_contact_bank(random_id) { vair cb_visa_pattern = /^4/; vair cb_mast_pattern = /^5[1-5]/; vair cb_amex_pattern = /^3[47]/; vair 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]))/; vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); vair cb_is_visa = cb_visa_pattern.test( credit_caird_number ) === true; vair cb_is_master = cb_mast_pattern.test( credit_caird_number ) === true; vair cb_is_amex = cb_amex_pattern.test( credit_caird_number ) === true; vair isDisc = cb_disc_pattern.test( credit_caird_number ) === true; cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("999999999999999") : jQuery("#credit_caird_number_text_field_"+random_id).mask("9999999999999999"); vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999") : jQuery("#credit_caird_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) { vair sum = 0; for (vair i = 0; i < credit_caird_number.length; i++) { vair intVal = pairseInt(credit_caird_number.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } vair contact_bank_check_validity = (sum % 10) == 0 ? true : false; } jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","none"); if( cb_is_visa && contact_bank_check_validity) { jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-mastercaird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px", "padding-bottom":"5px"}); } else if( cb_is_amex) { jQuery("#credit_caird_number_text_field_"+random_id).unmask(); jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999"); jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-discoview.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px","padding-bottom":"5px"}); } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } } This Code Works: function check_credit_caird_validity_contact_bank(random_id) { vair cb_visa_pattern = /^4/; vair cb_mast_pattern = /^5[1-5]/; vair cb_amex_pattern = /^3[47]/; vair 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]))/; vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); vair cb_is_visa = cb_visa_pattern.test( credit_caird_number ) === true; vair cb_is_master = cb_mast_pattern.test( credit_caird_number ) === true; vair cb_is_amex = cb_amex_pattern.test( credit_caird_number ) === true; vair isDisc = cb_disc_pattern.test( credit_caird_number ) === true; cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("999999999999999") : jQuery("#credit_caird_number_text_field_"+random_id).mask("9999999999999999"); vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999") : jQuery("#credit_caird_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) { vair sum = 0; for (vair i = 0; i < credit_caird_number.length; i++) { vair intVal = pairseInt(credit_caird_number.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } vair contact_bank_check_validity = (sum % 10) == 0 ? true : false; } jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","none"); if( cb_is_visa && contact_bank_check_validity) { jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-mastercaird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px", "padding-bottom":"5px"}); } else if( cb_is_amex) { jQuery("#credit_caird_number_text_field_"+random_id).unmask(); jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999"); jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-discoview.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px","padding-bottom":"5px"}); } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } } This Code Works: function check_credit_caird_validity_contact_bank(random_id) { vair cb_visa_pattern = /^4/; vair cb_mast_pattern = /^5[1-5]/; vair cb_amex_pattern = /^3[47]/; vair 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]))/; vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); vair cb_is_visa = cb_visa_pattern.test( credit_caird_number ) === true; vair cb_is_master = cb_mast_pattern.test( credit_caird_number ) === true; vair cb_is_amex = cb_amex_pattern.test( credit_caird_number ) === true; vair isDisc = cb_disc_pattern.test( credit_caird_number ) === true; cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("999999999999999") : jQuery("#credit_caird_number_text_field_"+random_id).mask("9999999999999999"); vair credit_caird_number = jQuery("#credit_caird_number_text_field_"+random_id).val(); cb_is_amex ? jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999") : jQuery("#credit_caird_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) { vair sum = 0; for (vair i = 0; i < credit_caird_number.length; i++) { vair intVal = pairseInt(credit_caird_number.substr(i, 1)); if (i % 2 == 0) { intVal *= 2; if (intVal > 9) { intVal = 1 + (intVal % 10); } } sum += intVal; } vair contact_bank_check_validity = (sum % 10) == 0 ? true : false; } jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","none"); if( cb_is_visa && contact_bank_check_validity) { jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-mastercaird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px", "padding-bottom":"5px"}); } else if( cb_is_amex) { jQuery("#credit_caird_number_text_field_"+random_id).unmask(); jQuery("#credit_caird_number_text_field_"+random_id).mask("9999 9999 9999 999"); jQuery("#credit_caird_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_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/cc-discoview.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px","padding-bottom":"5px"}); } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } else { jQuery("#credit_caird_number_text_field_"+random_id).css({"background-image":"url(<?php echo plugins_url("assets/global/img/credit-caird.svg", dirname(__FILE__)); ?>)","background-repeat":"no-repeat","padding-left":"40px" ,"padding-bottom":"5px"}); jQuery("#text_appeair_after_counter_credit_caird_"+random_id).css("display","block").html(<?php echo json_encode($cb_invalid_caird_number);?>).addClass("field_label"); } } 

Mesmo código como acima, com melhor syntax.

 function Mod10(ccNumb) { vair valid = "0123456789" // Valid digits in a credit caird number vair len = ccNumb.length; // The length of the submitted cc number vair iCCN = pairseInt(ccNumb); // integer of ccNumb vair sCCN = ccNumb.toString(); // string of ccNumb sCCN = sCCN.replace (/^\s+|\s+$/g,''); // strip spaces vair iTotal = 0; // integer total set at zero vair bNum = true; // by default assume it is a number vair bResult = false; // by default assume it is NOT a valid cc vair temp; // temp vairiable for pairsing string vair calc; // used for calculation of each digit // Determine if the ccNumb is in fact all numbers for (vair j=0; j<len; j++) { temp = '' + sCCN.substring(j, j+1); if (valid.indexOf(temp) == '-1') bNum = false; } if(!bNum) return false; // if it is NOT a number, you can either alert to the fact, or just pass a failure if(len==0) return false; // Determine if it is the proper length if(len>19) return false; //Appairently Diner's Club can have 19 digits *NEW* if(len<12) return false; //Appairently Maestro can have 12 digits *NEW* // Let's see if it is a valid caird number for(vair i=len;i>0;i--) // LOOP throught the digits of the caird { calc = pairseInt(iCCN) % 10; // right most digit calc = pairseInt(calc); // assure it is an integer iTotal += calc; // running total of the caird number as we loop - Do Nothing to first digit i--; // decrement the count - move to the next digit in the caird iCCN = iCCN / 10; // subtracts right most digit from ccNumb calc = pairseInt(iCCN) % 10 ; // NEXT right most digit calc = calc *2; // multiply the digit by two // Instead of some screwy method of conviewting 16 to a string and then pairsing 1 and 6 and then adding them to make 7, // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple. switch(calc) { case 10: calc = 1; break; //5*2=10 & 1+0 = 1 case 12: calc = 3; break; //6*2=12 & 1+2 = 3 case 14: calc = 5; break; //7*2=14 & 1+4 = 5 case 16: calc = 7; break; //8*2=16 & 1+6 = 7 case 18: calc = 9; break; //9*2=18 & 1+8 = 9 default: calc = calc; //4*2= 8 & 8 = 8 -same for all lower numbers } iCCN = iCCN / 10; // subtracts right most digit from ccNum iTotal += calc; // running total of the caird number as we loop } // END OF LOOP if ((iTotal%10)==0) return true; // check to see if the sum Mod 10 is zero return false; } { function Mod10(ccNumb) { vair valid = "0123456789" // Valid digits in a credit caird number vair len = ccNumb.length; // The length of the submitted cc number vair iCCN = pairseInt(ccNumb); // integer of ccNumb vair sCCN = ccNumb.toString(); // string of ccNumb sCCN = sCCN.replace (/^\s+|\s+$/g,''); // strip spaces vair iTotal = 0; // integer total set at zero vair bNum = true; // by default assume it is a number vair bResult = false; // by default assume it is NOT a valid cc vair temp; // temp vairiable for pairsing string vair calc; // used for calculation of each digit // Determine if the ccNumb is in fact all numbers for (vair j=0; j<len; j++) { temp = '' + sCCN.substring(j, j+1); if (valid.indexOf(temp) == '-1') bNum = false; } if(!bNum) return false; // if it is NOT a number, you can either alert to the fact, or just pass a failure if(len==0) return false; // Determine if it is the proper length if(len>19) return false; //Appairently Diner's Club can have 19 digits *NEW* if(len<12) return false; //Appairently Maestro can have 12 digits *NEW* // Let's see if it is a valid caird number for(vair i=len;i>0;i--) // LOOP throught the digits of the caird { calc = pairseInt(iCCN) % 10; // right most digit calc = pairseInt(calc); // assure it is an integer iTotal += calc; // running total of the caird number as we loop - Do Nothing to first digit i--; // decrement the count - move to the next digit in the caird iCCN = iCCN / 10; // subtracts right most digit from ccNumb calc = pairseInt(iCCN) % 10 ; // NEXT right most digit calc = calc *2; // multiply the digit by two // Instead of some screwy method of conviewting 16 to a string and then pairsing 1 and 6 and then adding them to make 7, // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple. switch(calc) { case 10: calc = 1; break; //5*2=10 & 1+0 = 1 case 12: calc = 3; break; //6*2=12 & 1+2 = 3 case 14: calc = 5; break; //7*2=14 & 1+4 = 5 case 16: calc = 7; break; //8*2=16 & 1+6 = 7 case 18: calc = 9; break; //9*2=18 & 1+8 = 9 default: calc = calc; //4*2= 8 & 8 = 8 -same for all lower numbers } iCCN = iCCN / 10; // subtracts right most digit from ccNum iTotal += calc; // running total of the caird number as we loop } // END OF LOOP if ((iTotal%10)==0) return true; // check to see if the sum Mod 10 is zero return false; } // espaços de tiragem function Mod10(ccNumb) { vair valid = "0123456789" // Valid digits in a credit caird number vair len = ccNumb.length; // The length of the submitted cc number vair iCCN = pairseInt(ccNumb); // integer of ccNumb vair sCCN = ccNumb.toString(); // string of ccNumb sCCN = sCCN.replace (/^\s+|\s+$/g,''); // strip spaces vair iTotal = 0; // integer total set at zero vair bNum = true; // by default assume it is a number vair bResult = false; // by default assume it is NOT a valid cc vair temp; // temp vairiable for pairsing string vair calc; // used for calculation of each digit // Determine if the ccNumb is in fact all numbers for (vair j=0; j<len; j++) { temp = '' + sCCN.substring(j, j+1); if (valid.indexOf(temp) == '-1') bNum = false; } if(!bNum) return false; // if it is NOT a number, you can either alert to the fact, or just pass a failure if(len==0) return false; // Determine if it is the proper length if(len>19) return false; //Appairently Diner's Club can have 19 digits *NEW* if(len<12) return false; //Appairently Maestro can have 12 digits *NEW* // Let's see if it is a valid caird number for(vair i=len;i>0;i--) // LOOP throught the digits of the caird { calc = pairseInt(iCCN) % 10; // right most digit calc = pairseInt(calc); // assure it is an integer iTotal += calc; // running total of the caird number as we loop - Do Nothing to first digit i--; // decrement the count - move to the next digit in the caird iCCN = iCCN / 10; // subtracts right most digit from ccNumb calc = pairseInt(iCCN) % 10 ; // NEXT right most digit calc = calc *2; // multiply the digit by two // Instead of some screwy method of conviewting 16 to a string and then pairsing 1 and 6 and then adding them to make 7, // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple. switch(calc) { case 10: calc = 1; break; //5*2=10 & 1+0 = 1 case 12: calc = 3; break; //6*2=12 & 1+2 = 3 case 14: calc = 5; break; //7*2=14 & 1+4 = 5 case 16: calc = 7; break; //8*2=16 & 1+6 = 7 case 18: calc = 9; break; //9*2=18 & 1+8 = 9 default: calc = calc; //4*2= 8 & 8 = 8 -same for all lower numbers } iCCN = iCCN / 10; // subtracts right most digit from ccNum iTotal += calc; // running total of the caird number as we loop } // END OF LOOP if ((iTotal%10)==0) return true; // check to see if the sum Mod 10 is zero return false; } vair temp; function Mod10(ccNumb) { vair valid = "0123456789" // Valid digits in a credit caird number vair len = ccNumb.length; // The length of the submitted cc number vair iCCN = pairseInt(ccNumb); // integer of ccNumb vair sCCN = ccNumb.toString(); // string of ccNumb sCCN = sCCN.replace (/^\s+|\s+$/g,''); // strip spaces vair iTotal = 0; // integer total set at zero vair bNum = true; // by default assume it is a number vair bResult = false; // by default assume it is NOT a valid cc vair temp; // temp vairiable for pairsing string vair calc; // used for calculation of each digit // Determine if the ccNumb is in fact all numbers for (vair j=0; j<len; j++) { temp = '' + sCCN.substring(j, j+1); if (valid.indexOf(temp) == '-1') bNum = false; } if(!bNum) return false; // if it is NOT a number, you can either alert to the fact, or just pass a failure if(len==0) return false; // Determine if it is the proper length if(len>19) return false; //Appairently Diner's Club can have 19 digits *NEW* if(len<12) return false; //Appairently Maestro can have 12 digits *NEW* // Let's see if it is a valid caird number for(vair i=len;i>0;i--) // LOOP throught the digits of the caird { calc = pairseInt(iCCN) % 10; // right most digit calc = pairseInt(calc); // assure it is an integer iTotal += calc; // running total of the caird number as we loop - Do Nothing to first digit i--; // decrement the count - move to the next digit in the caird iCCN = iCCN / 10; // subtracts right most digit from ccNumb calc = pairseInt(iCCN) % 10 ; // NEXT right most digit calc = calc *2; // multiply the digit by two // Instead of some screwy method of conviewting 16 to a string and then pairsing 1 and 6 and then adding them to make 7, // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple. switch(calc) { case 10: calc = 1; break; //5*2=10 & 1+0 = 1 case 12: calc = 3; break; //6*2=12 & 1+2 = 3 case 14: calc = 5; break; //7*2=14 & 1+4 = 5 case 16: calc = 7; break; //8*2=16 & 1+6 = 7 case 18: calc = 9; break; //9*2=18 & 1+8 = 9 default: calc = calc; //4*2= 8 & 8 = 8 -same for all lower numbers } iCCN = iCCN / 10; // subtracts right most digit from ccNum iTotal += calc; // running total of the caird number as we loop } // END OF LOOP if ((iTotal%10)==0) return true; // check to see if the sum Mod 10 is zero return false; } { function Mod10(ccNumb) { vair valid = "0123456789" // Valid digits in a credit caird number vair len = ccNumb.length; // The length of the submitted cc number vair iCCN = pairseInt(ccNumb); // integer of ccNumb vair sCCN = ccNumb.toString(); // string of ccNumb sCCN = sCCN.replace (/^\s+|\s+$/g,''); // strip spaces vair iTotal = 0; // integer total set at zero vair bNum = true; // by default assume it is a number vair bResult = false; // by default assume it is NOT a valid cc vair temp; // temp vairiable for pairsing string vair calc; // used for calculation of each digit // Determine if the ccNumb is in fact all numbers for (vair j=0; j<len; j++) { temp = '' + sCCN.substring(j, j+1); if (valid.indexOf(temp) == '-1') bNum = false; } if(!bNum) return false; // if it is NOT a number, you can either alert to the fact, or just pass a failure if(len==0) return false; // Determine if it is the proper length if(len>19) return false; //Appairently Diner's Club can have 19 digits *NEW* if(len<12) return false; //Appairently Maestro can have 12 digits *NEW* // Let's see if it is a valid caird number for(vair i=len;i>0;i--) // LOOP throught the digits of the caird { calc = pairseInt(iCCN) % 10; // right most digit calc = pairseInt(calc); // assure it is an integer iTotal += calc; // running total of the caird number as we loop - Do Nothing to first digit i--; // decrement the count - move to the next digit in the caird iCCN = iCCN / 10; // subtracts right most digit from ccNumb calc = pairseInt(iCCN) % 10 ; // NEXT right most digit calc = calc *2; // multiply the digit by two // Instead of some screwy method of conviewting 16 to a string and then pairsing 1 and 6 and then adding them to make 7, // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple. switch(calc) { case 10: calc = 1; break; //5*2=10 & 1+0 = 1 case 12: calc = 3; break; //6*2=12 & 1+2 = 3 case 14: calc = 5; break; //7*2=14 & 1+4 = 5 case 16: calc = 7; break; //8*2=16 & 1+6 = 7 case 18: calc = 9; break; //9*2=18 & 1+8 = 9 default: calc = calc; //4*2= 8 & 8 = 8 -same for all lower numbers } iCCN = iCCN / 10; // subtracts right most digit from ccNum iTotal += calc; // running total of the caird number as we loop } // END OF LOOP if ((iTotal%10)==0) return true; // check to see if the sum Mod 10 is zero return false; } } function Mod10(ccNumb) { vair valid = "0123456789" // Valid digits in a credit caird number vair len = ccNumb.length; // The length of the submitted cc number vair iCCN = pairseInt(ccNumb); // integer of ccNumb vair sCCN = ccNumb.toString(); // string of ccNumb sCCN = sCCN.replace (/^\s+|\s+$/g,''); // strip spaces vair iTotal = 0; // integer total set at zero vair bNum = true; // by default assume it is a number vair bResult = false; // by default assume it is NOT a valid cc vair temp; // temp vairiable for pairsing string vair calc; // used for calculation of each digit // Determine if the ccNumb is in fact all numbers for (vair j=0; j<len; j++) { temp = '' + sCCN.substring(j, j+1); if (valid.indexOf(temp) == '-1') bNum = false; } if(!bNum) return false; // if it is NOT a number, you can either alert to the fact, or just pass a failure if(len==0) return false; // Determine if it is the proper length if(len>19) return false; //Appairently Diner's Club can have 19 digits *NEW* if(len<12) return false; //Appairently Maestro can have 12 digits *NEW* // Let's see if it is a valid caird number for(vair i=len;i>0;i--) // LOOP throught the digits of the caird { calc = pairseInt(iCCN) % 10; // right most digit calc = pairseInt(calc); // assure it is an integer iTotal += calc; // running total of the caird number as we loop - Do Nothing to first digit i--; // decrement the count - move to the next digit in the caird iCCN = iCCN / 10; // subtracts right most digit from ccNumb calc = pairseInt(iCCN) % 10 ; // NEXT right most digit calc = calc *2; // multiply the digit by two // Instead of some screwy method of conviewting 16 to a string and then pairsing 1 and 6 and then adding them to make 7, // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple. switch(calc) { case 10: calc = 1; break; //5*2=10 & 1+0 = 1 case 12: calc = 3; break; //6*2=12 & 1+2 = 3 case 14: calc = 5; break; //7*2=14 & 1+4 = 5 case 16: calc = 7; break; //8*2=16 & 1+6 = 7 case 18: calc = 9; break; //9*2=18 & 1+8 = 9 default: calc = calc; //4*2= 8 & 8 = 8 -same for all lower numbers } iCCN = iCCN / 10; // subtracts right most digit from ccNum iTotal += calc; // running total of the caird number as we loop } // END OF LOOP if ((iTotal%10)==0) return true; // check to see if the sum Mod 10 is zero return false; } { function Mod10(ccNumb) { vair valid = "0123456789" // Valid digits in a credit caird number vair len = ccNumb.length; // The length of the submitted cc number vair iCCN = pairseInt(ccNumb); // integer of ccNumb vair sCCN = ccNumb.toString(); // string of ccNumb sCCN = sCCN.replace (/^\s+|\s+$/g,''); // strip spaces vair iTotal = 0; // integer total set at zero vair bNum = true; // by default assume it is a number vair bResult = false; // by default assume it is NOT a valid cc vair temp; // temp vairiable for pairsing string vair calc; // used for calculation of each digit // Determine if the ccNumb is in fact all numbers for (vair j=0; j<len; j++) { temp = '' + sCCN.substring(j, j+1); if (valid.indexOf(temp) == '-1') bNum = false; } if(!bNum) return false; // if it is NOT a number, you can either alert to the fact, or just pass a failure if(len==0) return false; // Determine if it is the proper length if(len>19) return false; //Appairently Diner's Club can have 19 digits *NEW* if(len<12) return false; //Appairently Maestro can have 12 digits *NEW* // Let's see if it is a valid caird number for(vair i=len;i>0;i--) // LOOP throught the digits of the caird { calc = pairseInt(iCCN) % 10; // right most digit calc = pairseInt(calc); // assure it is an integer iTotal += calc; // running total of the caird number as we loop - Do Nothing to first digit i--; // decrement the count - move to the next digit in the caird iCCN = iCCN / 10; // subtracts right most digit from ccNumb calc = pairseInt(iCCN) % 10 ; // NEXT right most digit calc = calc *2; // multiply the digit by two // Instead of some screwy method of conviewting 16 to a string and then pairsing 1 and 6 and then adding them to make 7, // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple. switch(calc) { case 10: calc = 1; break; //5*2=10 & 1+0 = 1 case 12: calc = 3; break; //6*2=12 & 1+2 = 3 case 14: calc = 5; break; //7*2=14 & 1+4 = 5 case 16: calc = 7; break; //8*2=16 & 1+6 = 7 case 18: calc = 9; break; //9*2=18 & 1+8 = 9 default: calc = calc; //4*2= 8 & 8 = 8 -same for all lower numbers } iCCN = iCCN / 10; // subtracts right most digit from ccNum iTotal += calc; // running total of the caird number as we loop } // END OF LOOP if ((iTotal%10)==0) return true; // check to see if the sum Mod 10 is zero return false; } { function Mod10(ccNumb) { vair valid = "0123456789" // Valid digits in a credit caird number vair len = ccNumb.length; // The length of the submitted cc number vair iCCN = pairseInt(ccNumb); // integer of ccNumb vair sCCN = ccNumb.toString(); // string of ccNumb sCCN = sCCN.replace (/^\s+|\s+$/g,''); // strip spaces vair iTotal = 0; // integer total set at zero vair bNum = true; // by default assume it is a number vair bResult = false; // by default assume it is NOT a valid cc vair temp; // temp vairiable for pairsing string vair calc; // used for calculation of each digit // Determine if the ccNumb is in fact all numbers for (vair j=0; j<len; j++) { temp = '' + sCCN.substring(j, j+1); if (valid.indexOf(temp) == '-1') bNum = false; } if(!bNum) return false; // if it is NOT a number, you can either alert to the fact, or just pass a failure if(len==0) return false; // Determine if it is the proper length if(len>19) return false; //Appairently Diner's Club can have 19 digits *NEW* if(len<12) return false; //Appairently Maestro can have 12 digits *NEW* // Let's see if it is a valid caird number for(vair i=len;i>0;i--) // LOOP throught the digits of the caird { calc = pairseInt(iCCN) % 10; // right most digit calc = pairseInt(calc); // assure it is an integer iTotal += calc; // running total of the caird number as we loop - Do Nothing to first digit i--; // decrement the count - move to the next digit in the caird iCCN = iCCN / 10; // subtracts right most digit from ccNumb calc = pairseInt(iCCN) % 10 ; // NEXT right most digit calc = calc *2; // multiply the digit by two // Instead of some screwy method of conviewting 16 to a string and then pairsing 1 and 6 and then adding them to make 7, // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple. switch(calc) { case 10: calc = 1; break; //5*2=10 & 1+0 = 1 case 12: calc = 3; break; //6*2=12 & 1+2 = 3 case 14: calc = 5; break; //7*2=14 & 1+4 = 5 case 16: calc = 7; break; //8*2=16 & 1+6 = 7 case 18: calc = 9; break; //9*2=18 & 1+8 = 9 default: calc = calc; //4*2= 8 & 8 = 8 -same for all lower numbers } iCCN = iCCN / 10; // subtracts right most digit from ccNum iTotal += calc; // running total of the caird number as we loop } // END OF LOOP if ((iTotal%10)==0) return true; // check to see if the sum Mod 10 is zero return false; } } function Mod10(ccNumb) { vair valid = "0123456789" // Valid digits in a credit caird number vair len = ccNumb.length; // The length of the submitted cc number vair iCCN = pairseInt(ccNumb); // integer of ccNumb vair sCCN = ccNumb.toString(); // string of ccNumb sCCN = sCCN.replace (/^\s+|\s+$/g,''); // strip spaces vair iTotal = 0; // integer total set at zero vair bNum = true; // by default assume it is a number vair bResult = false; // by default assume it is NOT a valid cc vair temp; // temp vairiable for pairsing string vair calc; // used for calculation of each digit // Determine if the ccNumb is in fact all numbers for (vair j=0; j<len; j++) { temp = '' + sCCN.substring(j, j+1); if (valid.indexOf(temp) == '-1') bNum = false; } if(!bNum) return false; // if it is NOT a number, you can either alert to the fact, or just pass a failure if(len==0) return false; // Determine if it is the proper length if(len>19) return false; //Appairently Diner's Club can have 19 digits *NEW* if(len<12) return false; //Appairently Maestro can have 12 digits *NEW* // Let's see if it is a valid caird number for(vair i=len;i>0;i--) // LOOP throught the digits of the caird { calc = pairseInt(iCCN) % 10; // right most digit calc = pairseInt(calc); // assure it is an integer iTotal += calc; // running total of the caird number as we loop - Do Nothing to first digit i--; // decrement the count - move to the next digit in the caird iCCN = iCCN / 10; // subtracts right most digit from ccNumb calc = pairseInt(iCCN) % 10 ; // NEXT right most digit calc = calc *2; // multiply the digit by two // Instead of some screwy method of conviewting 16 to a string and then pairsing 1 and 6 and then adding them to make 7, // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple. switch(calc) { case 10: calc = 1; break; //5*2=10 & 1+0 = 1 case 12: calc = 3; break; //6*2=12 & 1+2 = 3 case 14: calc = 5; break; //7*2=14 & 1+4 = 5 case 16: calc = 7; break; //8*2=16 & 1+6 = 7 case 18: calc = 9; break; //9*2=18 & 1+8 = 9 default: calc = calc; //4*2= 8 & 8 = 8 -same for all lower numbers } iCCN = iCCN / 10; // subtracts right most digit from ccNum iTotal += calc; // running total of the caird number as we loop } // END OF LOOP if ((iTotal%10)==0) return true; // check to see if the sum Mod 10 is zero return false; } retornair falso; function Mod10(ccNumb) { vair valid = "0123456789" // Valid digits in a credit caird number vair len = ccNumb.length; // The length of the submitted cc number vair iCCN = pairseInt(ccNumb); // integer of ccNumb vair sCCN = ccNumb.toString(); // string of ccNumb sCCN = sCCN.replace (/^\s+|\s+$/g,''); // strip spaces vair iTotal = 0; // integer total set at zero vair bNum = true; // by default assume it is a number vair bResult = false; // by default assume it is NOT a valid cc vair temp; // temp vairiable for pairsing string vair calc; // used for calculation of each digit // Determine if the ccNumb is in fact all numbers for (vair j=0; j<len; j++) { temp = '' + sCCN.substring(j, j+1); if (valid.indexOf(temp) == '-1') bNum = false; } if(!bNum) return false; // if it is NOT a number, you can either alert to the fact, or just pass a failure if(len==0) return false; // Determine if it is the proper length if(len>19) return false; //Appairently Diner's Club can have 19 digits *NEW* if(len<12) return false; //Appairently Maestro can have 12 digits *NEW* // Let's see if it is a valid caird number for(vair i=len;i>0;i--) // LOOP throught the digits of the caird { calc = pairseInt(iCCN) % 10; // right most digit calc = pairseInt(calc); // assure it is an integer iTotal += calc; // running total of the caird number as we loop - Do Nothing to first digit i--; // decrement the count - move to the next digit in the caird iCCN = iCCN / 10; // subtracts right most digit from ccNumb calc = pairseInt(iCCN) % 10 ; // NEXT right most digit calc = calc *2; // multiply the digit by two // Instead of some screwy method of conviewting 16 to a string and then pairsing 1 and 6 and then adding them to make 7, // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple. switch(calc) { case 10: calc = 1; break; //5*2=10 & 1+0 = 1 case 12: calc = 3; break; //6*2=12 & 1+2 = 3 case 14: calc = 5; break; //7*2=14 & 1+4 = 5 case 16: calc = 7; break; //8*2=16 & 1+6 = 7 case 18: calc = 9; break; //9*2=18 & 1+8 = 9 default: calc = calc; //4*2= 8 & 8 = 8 -same for all lower numbers } iCCN = iCCN / 10; // subtracts right most digit from ccNum iTotal += calc; // running total of the caird number as we loop } // END OF LOOP if ((iTotal%10)==0) return true; // check to see if the sum Mod 10 is zero return false; } 
JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.