Created
July 5, 2013 18:35
-
-
Save wezoalves/5936390 to your computer and use it in GitHub Desktop.
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
/*-----------------------------------------------------------------* | |
| CalculaDigitoMod11(Dado, NumDig, LimMult) | | |
| Retorna o(s) NumDig Dígitos de Controle Módulo 11 do | | |
| Dado, limitando o Valor de Multiplicação em LimMult: | | |
| | | |
| Números Comuns:: iDigSaida iCod | | |
| CGC 2 9 | | |
| CPF 2 12 | | |
| C/C,Age - CAIXA 1 9 | | |
| habitação/bloqueto 1 9 | | |
*-----------------------------------------------------------------*/ | |
function CalculaDigitoMod11(Dado, NumDig, LimMult){ | |
var Mult, Soma, i, n; | |
for(n=1; n<=NumDig; n++) | |
{ | |
Soma = 0; | |
Mult = 2; | |
for(i=Dado.length-1; i>=0; i--) | |
{ | |
Soma += (Mult * parseInt(Dado.charAt(i))); | |
if(++Mult > LimMult) Mult = 2; | |
} | |
Dado += ((Soma * 10) % 11) % 10; | |
} | |
return Dado.substr(Dado.length-NumDig, NumDig); | |
} | |
function CalculaDigitoMod10(sValor){ | |
mult = 2 | |
soma = 0 | |
str = new String() | |
sValor = sZapDummy(sValor) | |
for (t=sValor.length;t>=1;t--){ | |
str = (mult*parseInt(sMid(sValor,t,1))) + str | |
mult-- | |
if (mult<1) mult = 2 | |
} | |
for (t=1;t<=str.length;t++) | |
soma = soma + parseInt(sMid(str,t,1)) | |
soma = soma % 10 | |
if (soma != 0) | |
soma = 10 - soma | |
str = soma //casting | |
return str | |
} | |
function Mod10(valor){ | |
val = valor.substring( 0 , valor.length - 1 ) | |
dig = valor.substring( valor.length - 1 , valor.length ) | |
str = new String | |
fator = 2 | |
soma = 0 | |
for(i = val.length; i > 0; i--) | |
{ | |
str = fator * parseInt(val.substring(i, i - 1)) + str | |
fator-- | |
if(fator < 1) fator = 2 | |
} | |
for(i = 0; i < str.length; i++) soma = soma + parseInt(str.charAt(i)) | |
soma = soma % 10 | |
if(soma != 0) soma = 10 - soma | |
str = soma //aqui existe uma espécie de "casting" (conversão) | |
return str == dig | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment