Created
May 8, 2013 14:42
-
-
Save krypton/5540919 to your computer and use it in GitHub Desktop.
Javascript NIB (Bank Identification Number) Validation
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 validateNIB(t, max_len) | |
{ | |
var pesos = [0, 1, 10, 3, 30, 9, 90, 27, 76, 81, 34, 49, 5, 50, 15, 53, 45, 62, 38, 89, 17, 73, 51, 25, 56, 75, 71, 31, 19, 93, 57], | |
validateValue = t.toString(), | |
s = validateValue.split(''), | |
r = s.reverse(), | |
tot = 0; | |
if (t == undefined) { | |
return false; | |
} | |
if (validateValue.length <= 0 || validateValue.length != max_len) { | |
return false; | |
} | |
for (var i = 2; i < r.length; i++) { | |
tot += r[parseInt(i)] * pesos[(parseInt(i)+1)]; | |
} | |
var resto = (tot % 97), | |
val = parseInt(98 - resto); | |
if (val == parseInt(validateValue.substring((validateValue.length - 2)), 10)) { | |
return true; | |
} else { | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment