Created
November 24, 2017 09:48
-
-
Save mhf-ir/c17374fae395a57c9f8e5fe7a92bbf23 to your computer and use it in GitHub Desktop.
iranian sheba bank validation javascript | اعتبار سنجی کد شبا با جاوا اسکریپت
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function iso7064Mod97_10(iban) { | |
var remainder = iban, | |
block; | |
while (remainder.length > 2){ | |
block = remainder.slice(0, 9); | |
remainder = parseInt(block, 10) % 97 + remainder.slice(block.length); | |
} | |
return parseInt(remainder, 10) % 97; | |
} | |
function validateIranianSheba(str) { | |
var pattern = /IR[0-9]{24}/; | |
if (str.length !== 26) { | |
return false; | |
} | |
if (!pattern.test(str)) { | |
return false; | |
} | |
var newStr = str.substr(4); | |
var d1 = str.charCodeAt(0) - 65 + 10; | |
var d2 = str.charCodeAt(1) - 65 + 10; | |
newStr += d1.toString() + d2.toString() + str.substr(2, 2); | |
var remainder = iso7064Mod97_10(newStr); | |
if (remainder !== 1) { | |
return false; | |
} | |
return true; | |
}; | |
console.log(validateIranianSheba('ENTER SHEBA NUMBER HERE IT\'SRETURN TRUE OR FALSE')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great job
@hasanparasteh
The last statement in the validateIranianSheba function could also be simplified to:
return iso7064Mod97_10(testString) !== 1