Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
اعتبار سنجی کارت عابر بانک ایران در جاوا اسکریپت \ Validation function of Iranian bank cards in Javascript \ تابع تشخیص صحت کارت عابربانک
"use strict";
// By Mahmoud Eskandari @ MIT license
function validateCard(card) {
if (typeof card === 'undefined'
|| card === null
|| card.length !== 16) {
return false;
}
let cardTotal = 0;
for (let i = 0; i < 16; i += 1) {
const c = Number(card[i]);
if (i % 2 === 0) {
cardTotal += ((c * 2 > 9) ? (c * 2) - 9 : (c * 2));
} else {
cardTotal += c;
}
}
return (cardTotal % 10 === 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment