Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

mestre fyoda

Validação de Inscrição Estadual

Recommended Posts

ie.html

<html><head><script language="javascript" type="text/javascript" src="ie.js"></script><script>function valida_ie() {	var ie =   document.getElementById('ie').value;	var estado = document.getElementById('estado').value;	if (CheckIE(ie , estado)){	}else{		alert('Inscrição Estadual errada.');	document.getElementById('ie').focus();	}}</script></head><body> <form> <input name="ie" type="text" id="ie" onkeypress="return MM_formtCep(event,this,'###.###.###.###');" size="20" maxlength="20" >	<select name="estado" class="style10" id="estado" onblur ="valida_ie();">	   <option value="AC">AC</option>	   <option value="AL">AL</option>	   <option value="AM">AM</option>	   <option value="AP">AP</option>	   <option value="BA">BA</option>	   <option value="CE">CE</option>	   <option value="ES">ES</option>	   <option value="GO">GO</option>	   <option value="MA">MA</option>	   <option value="MG">MG</option>	   <option value="MS">MS</option>	   <option value="PB">PB</option>	   <option value="PE">PE</option>	   <option value="PI">PI</option>	   <option value="PR">PR</option>	   <option value="RJ">RJ</option>	   <option value="RN">RN</option>	   <option value="RS">RS</option>	   <option value="RO">RO</option>	   <option value="RR">RR</option>	   <option value="SC">SC</option>	   <option value="SE">SE</option>	   <option value="SP">SP</option>	   <option value="TO">TO</option>	 </select><input type="button" value="Validar"></form></body></html>

 

ie.js

 

var OrdZero = '0'.charCodeAt(0);function CharToInt(ch){return ch.charCodeAt(0) - OrdZero;}function IntToChar(intt){return String.fromCharCode(intt + OrdZero);}function CheckIEAC(ie){if (ie.length != 13)return false;var b = 4, soma = 0;for (var i = 0; i <= 10; i++){soma += CharToInt(ie.charAt(i)) * b;--b;if (b == 1) { b = 9; }}dig = 11 - (soma % 11);if (dig >= 10) { dig = 0; }resultado = (IntToChar(dig) == ie.charAt(11));if (!resultado) { return false; }b = 5;soma = 0;for (var i = 0; i <= 11; i++){soma += CharToInt(ie.charAt(i)) * b;--b;if (b == 1) { b = 9; }}dig = 11 - (soma % 11);if (dig >= 10) { dig = 0; }if (IntToChar(dig) == ie.charAt(12)) { return true; } else { return false; }} //ACfunction CheckIEAL(ie){if (ie.length != 9)  return false;var b = 9, soma = 0;for (var i = 0; i <= 7; i++){   soma += CharToInt(ie.charAt(i)) * b;   --b;}soma *= 10;dig = soma - Math.floor(soma / 11) * 11;if (dig == 10) { dig = 0; }return (IntToChar(dig) == ie.charAt(8));} //ALfunction CheckIEAM(ie){if (ie.length != 9)  return false;var b = 9, soma = 0;for (var i = 0; i <= 7; i++){  soma += CharToInt(ie.charAt(i)) * b;  b--;}if (soma < 11) { dig = 11 - soma; } else {    i = soma % 11;   if (i <= 1) { dig = 0; } else { dig = 11 - i; }}return (IntToChar(dig) == ie.charAt(8));} //amfunction CheckIEAP(ie){if (ie.length != 9)  return false;var p = 0, d = 0, i = ie.substring(1, 8);if ((i >= 3000001) && (i <= 3017000)){  p =5;  d = 0;}else if ((i >= 3017001) && (i <= 3019022)){  p = 9;  d = 1;}b = 9;soma = p;for (var i = 0; i <= 7; i++){  soma += CharToInt(ie.charAt(i)) * b;  b--;}dig = 11 - (soma % 11);if (dig == 10){   dig = 0;}else if (dig == 11){   dig = d;}return (IntToChar(dig) == ie.charAt(8));} //apfunction CheckIEBA(ie){if (ie.length != 8)  return false;die = ie.substring(0, 8);var nro = new Array(8);var dig = -1;for (var i = 0; i <= 7; i++){  nro[i] = CharToInt(die.charAt(i));}var NumMod = 0;if (String(nro[0]).match(/[0123458]/))   NumMod = 10;else   NumMod = 11;b = 7;soma = 0;for (i = 0; i <= 5; i++){  soma += nro[i] * b;  b--;}i = soma % NumMod;if (NumMod == 10){  if (i == 0) { dig = 0; } else { dig = NumMod - i; }}else{  if (i <= 1) { dig = 0; } else { dig = NumMod - i; }}resultado = (dig == nro[7]);if (!resultado) { return false; }b = 8;soma = 0;for (i = 0; i <= 5; i++){  soma += nro[i] * b;  b--;}soma += nro[7] * 2;i = soma % NumMod;if (NumMod == 10){  if (i == 0) { dig = 0; } else { dig = NumMod - i; }}else {  if (i <= 1) { dig = 0; } else { dig = NumMod - i; }}return (dig == nro[6]);} //bafunction CheckIECE(ie){if (ie.length > 9)  return false;die = ie;if (ie.length < 9){  while (die.length <= 8)   die = '0' + die;}var nro = Array(9);for (var i = 0; i <= 8; i++)  nro[i] = CharToInt(die[i]);b = 9;soma = 0;for (i = 0; i <= 7; i++){  soma += nro[i] * b;  b--; }dig = 11 - (soma % 11);if (dig >= 10)  dig = 0;return (dig == nro[8]);} //cefunction CheckIEDF(ie){if (ie.length != 13)  return false;var nro = new Array(13);for (var i = 0; i <= 12; i++)  nro[i] = CharToInt(ie.charAt(i));b = 4;soma = 0;for (i = 0; i <= 10; i++){  soma += nro[i] * b;  b--;  if (b == 1)   b = 9;}dig = 11 - (soma % 11);if (dig >= 10)  dig = 0;resultado = (dig == nro[11]);if (!resultado)  return false;  b = 5;soma = 0;for (i = 0; i <= 11; i++){  soma += nro[i] * b;  b--;  if (b == 1)   b = 9;}dig = 11 - (soma % 11);if (dig >= 10)  dig = 0;return (dig == nro[12]);}// CHRISTOPHE T. C. <wG @ codingz.info>function CheckIEES(ie){if (ie.length != 9)  return false;var nro = new Array(9);for (var i = 0; i <= 8; i++)  nro[i] = CharToInt(ie.charAt(i)); b = 9;soma = 0;for (i = 0; i <= 7; i++){  soma += nro[i] * b;  b--;}i = soma % 11;if (i < 2)  dig = 0;else  dig = 11 - i;return (dig == nro[8]);}function CheckIEGO(ie){if (ie.length != 9)  return false;s = ie.substring(0, 2);if ((s == '10') || (s == '11') || (s == '15')){  var nro = new Array(9);  for (var i = 0; i <= 8; i++)   nro[i] = CharToInt(ie.charAt(i));  n = Math.floor(ie / 10);  if (n = 11094402)  {   if ((nro[8] == 0) || (nro[8] == 1))return true;  }  b = 9;  soma = 0;  for (i = 0; i <= 7; i++)  {   soma += nro[i] * b;   b--;  }  i = soma % 11;  if (i == 0)   dig = 0;  else  {   if (i == 1)   {if ((n >= 10103105) && (n <= 10119997))  dig = 1;else  dig = 0;   }   elsedig = 11 - i;  }  return (dig == nro[8]);}}function CheckIEMA(ie){if (ie.length != 9)  return false;var nro = new Array(9); for (var i = 0; i <= 8; i++)  nro[i] = CharToInt(ie.charAt(i));b = 9;soma = 0;for (i = 0; i <= 7; i++){  soma += nro[i] * b;  b--;}i = soma % 11;if (i <= 1)  dig = 0;else  dig = 11 - i;return (dig == nro[8]);}function CheckIEMT(ie){if (ie.length < 9)  return false;die = ie;if (die.length < 11){  while (die.length <= 10)   die = '0' + die;  var nro = new Array(11);  for (var i = 0; i <= 10; i++)   nro[i] = CharToInt(die[i]);  b = 3;  soma = 0;  for (i = 0; i <= 9; i++)  {   soma += nro[i] * b;   b--;   if (b == 1)b = 9;  }  i = soma % 11;  if (i <= 1)   dig = 0;  else   dig = 11 - i;  return (dig == nro[10]);}} //muitofunction CheckIEMS(ie){if (ie.length != 9)  return false;if (ie.substring(0,2) != '28')  return false;var nro = new Array(9);for (var i = 0; i <= 8; i++)  nro[i] = CharToInt(ie.charAt(i));b = 9;soma = 0;for (i = 0; i <= 7; i++){  soma += nro[i] * b;  b--;}i = soma % 11;if (i <= 1)  dig = 0;else  dig = 11 - i;return (dig == nro[8]);} //msfunction CheckIEPA(ie){if (ie.length != 9)  return false;if (ie.substring(0, 2) != '15')  return false;var nro = new Array(9);for (var i = 0; i <= 8; i++)  nro[i] = CharToInt(ie.charAt(i));b = 9;soma = 0;for (i = 0; i <= 7; i++){  soma += nro[i] * b;  b--;}i = soma % 11;if (i <= 1)  dig = 0;else  dig = 11 - i;return (dig == nro[8]);} //prafunction CheckIEPB(ie){if (ie.length != 9)  return false;var nro = new Array(9);for (var i = 0; i <= 8; i++)  nro[i] = CharToInt(ie.charAt(i));b = 9;soma = 0;for (i = 0; i <= 7; i++){  soma += nro[i] * b;  b--;  }i = soma % 11;if (i <= 1)  dig = 0;else  dig = 11 - i;return (dig == nro[8]);} //pbfunction CheckIEPR(ie){if (ie.length != 10)  return false;var nro = new Array(10);for (var i = 0; i <= 9; i++)  nro[i] = CharToInt(ie.charAt(i));b = 3;soma = 0;for (i = 0; i <= 7; i++){  soma += nro[i] * b;  b--;  if (b == 1)   b = 7;}i = soma % 11;if (i <= 1)  dig = 0;else  dig = 11 - i;resultado = (dig == nro[8]);if (!resultado)  return false;b = 4;soma = 0;for (i = 0; i <= 8; i++){  soma += nro[i] * b;  b--;  if (b == 1)   b = 7;}i = soma % 11;if (i <= 1)  dig = 0;else  dig = 11 - i;return (dig == nro[9]);} //prfunction CheckIEPE(ie){if (ie.length != 14)  return false;var nro = new Array(14);for (var i = 0; i <= 13; i++)  nro[i] = CharToInt(ie.charAt(i));b = 5;soma = 0;for (i = 0; i <= 12; i++){  soma += nro[i] * b;  b--;  if (b == 0)   b = 9;}dig = 11 - (soma % 11);if (dig > 9)  dig = dig - 10;return (dig == nro[13]);} //pefunction CheckIEPI(ie){if (ie.length != 9)  return false;var nro = new Array(9);for (var i = 0; i <= 8; i++)  nro[i] = CharToInt(ie.charAt(i));b = 9;soma = 0;for (i = 0; i <= 7; i++){  soma += nro[i] * b;  b--;}i = soma % 11;if (i <= 1)  dig = 0;else  dig = 11 - i;return (dig == nro[8]);} //pifunction CheckIERJ(ie){if (ie.length != 8)  return false;var nro = new Array(8);for (var i = 0; i <= 7; i++)  nro[i] = CharToInt(ie.charAt(i));b = 2;soma = 0;for (i = 0; i <= 6; i++){  soma += nro[i] * b;  b--;  if (b == 1)   b = 7;}i = soma % 11;if (i <= 1)  dig = 0;else  dig = 11 - i;return (dig == nro[7]);} //rj// CHRISTOPHE T. C. <wG @ codingz.info>function CheckIERN(ie){if (ie.length != 9)  return false;var nro = new Array(9);for (var i = 0; i <= 8; i++)  nro[i] = CharToInt(ie.charAt(i));b = 9;soma = 0;for (i = 0; i <= 7; i++){  soma += nro[i] * b;  b--;}soma *= 10;dig = soma % 11;if (dig == 10)  dig = 0;return (dig == nro[8]);} //rnfunction CheckIERS(ie){if (ie.length != 10)  return false;i = ie.substring(0, 3);if ((i >= 1) && (i <= 467)){  var nro = new Array(10);  for (var i = 0; i <= 9; i++)   nro[i] = CharToInt(ie.charAt(i));  b = 2;  soma = 0;  for (i = 0; i <= 8; i++)  {   soma += nro[i] * b;   b--;   if (b == 1)b = 9;  }  dig = 11 - (soma % 11);  if (dig >= 10)   dig = 0;  return (dig == nro[9]);} //if i&&i} //rsfunction CheckIEROantigo(ie){if (ie.length != 9) { return false;}var nro = new Array(9);b=6;soma =0;for( var i = 3; i <= 8; i++) {	nro[i] = CharToInt(ie.charAt(i));		if( i != 8 ) {			soma = soma + ( nro[i] * b );			b--;		}}dig = 11 - (soma % 11);if (dig >= 10)  dig = dig - 10;return (dig == nro[8]);} //ro-antigafunction CheckIERO(ie){if (ie.length != 14) { return false;}var nro = new Array(14);b=6;soma=0;		for(var i=0; i <= 4; i++) {				nro[i] = CharToInt(ie.charAt(i));						soma = soma + ( nro[i] * b );				b--;		}		b=9;		for(var i=5; i <= 13; i++) {				nro[i] = CharToInt(ie.charAt(i));				if ( i != 13 ) {						soma = soma + ( nro[i] * b );				b--;				}		}						dig = 11 - ( soma % 11);														if (dig >= 10)								  dig = dig - 10;									return(dig == nro[13]);						} //ro novafunction CheckIERR(ie){if (ie.length != 9)  return false;if (ie.substring(0,2) != '24')  return false;var nro = new Array(9);for (var i = 0; i <= 8; i++)  nro[i] = CharToInt(ie.charAt(i));var soma = 0;var n = 0;for (i = 0; i <= 7; i++)  soma += nro[i] * ++n;dig = soma % 9;return (dig == nro[8]);} //rrfunction CheckIESC(ie){if (ie.length != 9)  return false;var nro = new Array(9);for (var i = 0; i <= 8; i++)  nro[i] = CharToInt(ie.charAt(i));b = 9;soma = 0;for (i = 0; i <= 7; i++){  soma += nro[i] * b;  b--;}i = soma % 11;if (i <= 1)  dig = 0;else  dig = 11 - i;return (dig == nro[8]);} //sc// CHRISTOPHE T. C. <wG @ codingz.info>function CheckIESP(ie){if (((ie.substring(0,1)).toUpperCase()) == 'P'){  s = ie.substring(1, 9);  var nro = new Array(12);  for (var i = 0; i <= 7; i++)   nro[i] = CharToInt(s[i]);  soma = (nro[0] * 1) + (nro[1] * 3) + (nro[2] * 4) + (nro[3] * 5) +   (nro[4] * 6) + (nro[5] * 7) + (nro[6] * 8) + (nro[7] * 10);  dig = soma % 11;  if (dig >= 10)   dig = 0;  resultado = (dig == nro[8]);  if (!resultado)   return false;}else{  if (ie.length < 12)   return false;  var nro = new Array(12);  for (var i = 0; i <= 11; i++)   nro[i] = CharToInt(ie.charAt(i));  soma = (nro[0] * 1) + (nro[1] * 3) + (nro[2] * 4) + (nro[3] * 5) +   (nro[4] * 6) + (nro[5] * 7) + (nro[6] * 8) + (nro[7] * 10);  dig = soma % 11;  if (dig >= 10)   dig = 0;  resultado = (dig == nro[8]);  if (!resultado)   return false;  soma = (nro[0] * 3) + (nro[1] * 2) + (nro[2] * 10) + (nro[3] * 9) +   (nro[4] * 8) + (nro[5] * 7) + (nro[6] * 6)  + (nro[7] * 5) +   (nro[8] * 4) + (nro[9] * 3) + (nro[10] * 2);  dig = soma % 11;  if (dig >= 10)   dig = 0;  return (dig == nro[11]);}} //spfunction CheckIESE(ie){if (ie.length != 9)  return false;var nro = new Array(9);for (var i = 0; i <= 8; i++)  nro[i] = CharToInt(ie.charAt(i));b = 9;soma = 0;for (i = 0; i <= 7; i++){  soma += nro[i] * b;  b--;}dig = 11 - (soma % 11);if (dig >= 10)  dig = 0;return (dig == nro[8]);} //sefunction CheckIETO(ie){if (ie.length != 9) { return false;}var nro = new Array(9);b=9;soma=0;for (var i=0; i <= 8; i++ ) {nro[i] = CharToInt(ie.charAt(i));if(i != 8) {soma = soma + ( nro[i] * b );b--;}}ver = soma % 11;if ( ver < 2 )dig=0;if ( ver >= 2 )dig = 11 - ver;return(dig == nro[8]);} //to//inscrição estadual antigafunction CheckIETOantigo(ie){ if ( ie.length != 11 ) {	return false;}var nro = new Array(11);b=9;soma=0;s = ie.substring(2, 4);	if( s != '01' || s != '02' || s != '03' || s != '99' ) {		for ( var i=0; i <= 10; i++) 		{			nro[i] = CharToInt(ie.charAt(i));				if( i != 3 || i != 4) {			soma = soma + ( nro[i] * b );			b--;						} // if ( i != 3 || i != 4 )		} //fecha for			resto = soma % 11;									if( resto < 2 ) {						dig = 0;				}				if ( resto >= 2 ) {					dig = 11 - resto;				}							return (dig == nro[10]);	} // fecha if}//fecha função CheckIETOantigafunction CheckIEMG(ie){if (ie.substring(0,2) == 'PR')  return true;if (ie.substring(0,5) == 'ISENT')  return true;if (ie.length != 13)  return false;dig1 = ie.substring(11, 12);dig2 = ie.substring(12, 13);inscC = ie.substring(0, 3) + '0' + ie.substring(3, 11);insc=inscC.split('');npos = 11;i = 1;ptotal = 0;psoma = 0;while (npos >= 0){  i++;  psoma = CharToInt(insc[npos]) * i;    if (psoma >= 10)   psoma -= 9;  ptotal += psoma;  if (i == 2)   i = 0;  npos--;}nresto = ptotal % 10;if (nresto == 0)  nresto = 10;nresto = 10 - nresto;if (nresto != CharToInt(dig1))  return false;npos = 11;i = 1;ptotal = 0;is=ie.split('');while (npos >= 0){  i++;  if (i == 12)   i = 2;  ptotal += CharToInt(is[npos]) * i;  npos--;}nresto = ptotal % 11;if ((nresto == 0) || (nresto == 1))  nresto = 11;nresto = 11 - nresto;  return (nresto == CharToInt(dig2));}function CheckIE(ie, estado){ie = ie.replace(/\./g, '');ie = ie.replace(/\\/g, '');ie = ie.replace(/\-/g, '');ie = ie.replace(/\//g, '');if ( ie == 'ISENTO')   return true;switch (estado){  case 'MG': return CheckIEMG(ie); break;  case 'AC': return CheckIEAC(ie); break;  case 'AL': return CheckIEAL(ie); break;  case 'AM': return CheckIEAM(ie); break;  case 'AP': return CheckIEAP(ie); break;  case 'BA': return CheckIEBA(ie); break;  case 'CE': return CheckIECE(ie); break;  case 'DF': return CheckIEDF(ie); break;  case 'ES': return CheckIEES(ie); break;  case 'GO': return CheckIEGO(ie); break;  case 'MA': return CheckIEMA(ie); break;  case 'muito': return CheckIEMT(ie); break;  case 'MS': return CheckIEMS(ie); break;  case 'pra': return CheckIEPA(ie); break;  case 'PB': return CheckIEPB(ie); break;  case 'PR': return CheckIEPR(ie); break;  case 'PE': return CheckIEPE(ie); break;  case 'PI': return CheckIEPI(ie); break;  case 'RJ': return CheckIERJ(ie); break;  case 'RN': return CheckIERN(ie); break;  case 'RS': return CheckIERS(ie); break;  case 'RO': return ((CheckIERO(ie)) || (CheckIEROantigo(ie))); break;  case 'RR': return CheckIERR(ie); break;  case 'SC': return CheckIESC(ie); break;  case 'SP': return CheckIESP(ie); break;  case 'SE': return CheckIESE(ie); break;  case 'TO': return ((CheckIETO(ie)) || (CheckIETOantigo(ie))); break;//return CheckIETO(ie); break;		 }}

Funciona no Internet Explorer 6.0 e Mozila FireFox 1.5

Compartilhar este post


Link para o post
Compartilhar em outros sites

Alow amigo.

Estou testando estado por estado...

 

Acabei de encontrar um erro:

Na checagem de Minas gerais, fiz umas alterações para dar certo:

 

 

Na hora que ele puxava "psoma = CharToInt(insc[npos]) * i; ", ele pegava uma posição do array insc[], mas insc não era array, dae eu transformei insc em array:

inscC = ie.substring(0, 3) + '0' + ie.substring(3, 11);

insc=inscC.split('');

 

A mesma cosa acontece no while de baixo "ptotal += CharToInt(ie[npos]) * i;", ele puxa uma posição do array ie[], mas ie não é um array, e sim uma string, resolvi o problema da msm maneira:

is=ie.split('');

 

depois:

ptotal += CharToInt(is[npos]) * i;

 

Segue o código certo da função de validação de Minas Gerais:

 

function CheckIEMG(ie){if (ie.substring(0,2) == 'PR')  return true;if (ie.substring(0,5) == 'ISENT')  return true;if (ie.length != 13)  return false;dig1 = ie.substring(11, 12);dig2 = ie.substring(12, 13);inscC = ie.substring(0, 3) + '0' + ie.substring(3, 11);insc=inscC.split('');npos = 11;i = 1;ptotal = 0;psoma = 0;while (npos >= 0){  i++;  psoma = CharToInt(insc[npos]) * i;    if (psoma >= 10)   psoma -= 9;  ptotal += psoma;  if (i == 2)   i = 0;  npos--;}nresto = ptotal % 10;if (nresto == 0)  nresto = 10;nresto = 10 - nresto;if (nresto != CharToInt(dig1))  return false;npos = 11;i = 1;ptotal = 0;is=ie.split('');while (npos >= 0){  i++;  if (i == 12)   i = 2;  ptotal += CharToInt(is[npos]) * i;  npos--;}nresto = ptotal % 11;if ((nresto == 0) || (nresto == 1))  nresto = 11;nresto = 11 - nresto;  return (nresto == CharToInt(dig2));}

 

agora tá dando certo.

 

Já verifiquei SP, SC, RR, RO,RS,RJ, AC e essa de MG. Vou testar as outras e te respondo.

 

Abraços.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Seguinte, DF está ok. E a validação do AM também está ok.Só que tem um problema, peguei essas duas inscrições estaduais do Amazonas na net:04.193.980-313.200.275-8São de duas empresas. Elas não validam, pq o dígito está errado, o certo seria:04.193.980-3 (dígito 8)13.200.275-8 (dígito 2)Será que as inscrições que eu peguei estão erradas, pq eu olhei no site da Sintegra, e viz as contas do dígito, e deram certo.Abraços.

Compartilhar este post


Link para o post
Compartilhar em outros sites

beleza.. eu testei quase todos. Até agora deu tudo certo!!Só estão faltando do TO e do MT. Pq só esses?No site da Sintegra diz que são 10 dígitos. E na net, só achei inscrição estadual com 9 dígitos. Vai entender né. PReciso descobrira agora o que está certo.E quanto ao TO, não achei nenhuma inscrição estadual do Tocantins pra testar. Se alguém tiver ae.. me passa.Abraços.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Eu reverifiquei alguns IE.Eu apenas verifiquei TO E RO , e eles estavam bugados e ja consertei. eu vou atualizar o codigo q está no primeiro post se não vira bagunça.algum admin ou moderar que passar por esse topico por favor arrumem esse erro chato que fica dando toda ves q eu entro em algum link do forum imasters! isso ta ficando estressante.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.