Created
May 8, 2013 14:44
Revisions
-
Tiago Dias created this gist
May 8, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ function validateIBAN(iban) { var newIban = iban.toUpperCase(), modulo = function (divident, divisor) { var cDivident = ''; var cRest = ''; for (var i in divident ) { var cChar = divident[i]; var cOperator = cRest + '' + cDivident + '' + cChar; if ( cOperator < parseInt(divisor) ) { cDivident += '' + cChar; } else { cRest = cOperator % divisor; if ( cRest == 0 ) { cRest = ''; } cDivident = ''; } } cRest += '' + cDivident; if (cRest == '') { cRest = 0; } return cRest; }; if (newIban.search(/^[A-Z]{2}/gi) < 0) { return false; } newIban = newIban.substring(4) + newIban.substring(0, 4); newIban = newIban.replace(/[A-Z]/g, function (match) { return match.charCodeAt(0) - 55; }); return parseInt(modulo(newIban, 97), 10) === 1; }