Alguem sabe como verificar o título de eleitor em java?

alguem sabe como verificar o título de eleitor em java?

Lacerda,

O Título eleitoral não tem um dígito verificador ou algum algoritmo que o valide =(
Nem mesmo há um número específico de caracteres para o representar, como o CPF com 11 dígitos…

[]'s

Mas tem um ninja que fez em VB um esquema. Olhe aí:

[code]Private Function TituloOK(s As String) As Boolean

Dim DV1 As Integer
Dim DV2 As Integer
Dim i As Integer
Dim Total As Integer
Dim Resto As Integer
Dim Resto2 As Integer
Dim Numero As String

Numero = ""

For i = Len(s) To 12
  Numero = Numero + "0"
Next

Numero = Numero + s
TituloOK = False

DV1 = ((CInt(Mid(Numero, 1, 1)) * 2) + _
        (CInt(Mid(Numero, 2, 1)) * 9) + _
        (CInt(Mid(Numero, 3, 1)) * 8) + _
        (CInt(Mid(Numero, 4, 1)) * 7) + _
        (CInt(Mid(Numero, 5, 1)) * 6) + _
        (CInt(Mid(Numero, 6, 1)) * 5) + _
        (CInt(Mid(Numero, 7, 1)) * 4) + _
        (CInt(Mid(Numero, 8, 1)) * 3) + _
        (CInt(Mid(Numero, 9, 1)) * 2))
Resto = DV1 Mod 11

If Resto = 1 Then
    DV1 = 0
Else
    If Resto = 0 Then
        If (((Mid(Numero, 10, 2)) = "01") Or ((Mid(Numero, 10, 2)) = "02")) Then
            DV1 = 1
        Else
            DV1 = 0
        End If
    Else
        DV1 = 11 - Resto
    End If
End If

DV2 = ((CInt(Mid(Numero, 10, 1)) * 4) + (CInt(Mid(Numero, 11, 1)) * 3) + (DV1 * 2))
Resto2 = DV2 Mod 11

If Resto2 = 1 Then
    DV2 = 0
Else
    If Resto2 = 0 Then
        If (((Mid(Numero, 10, 2)) = "01") Or ((Mid(Numero, 10, 2)) = "02")) Then
            DV2 = 1
        Else
            DV2 = 0
        End If
    Else
        DV2 = 11 - Resto2
    End If
End If
    
If Mid(Numero, 12, 2) = (CStr(DV1) + CStr(DV2)) Then
  TituloOK = True
End If

End Function
[/code]

Olha outro código aí:

[code]function validaTIT(rcpf1) {
if (rcpf1.value.length == 0)
return true;

if( !( isInteger(rcpf1.value)) )
return aviso(rcpf1,“Título Eleitoral deve ser numérico.”);

if ( !(rcpf1.value.length == 13) )
PoeZeros(rcpf1,13);

rcpf2 = rcpf1.value.substr(11,2);
j = rcpf1.value.substr(9,2);

if ( (j<1) || (j>28) )
return aviso(rcpf1,“Título Eleitoral inválido.”)

d1 = 0;
for (i=0;i<9;i++)
d1 += rcpf1.value.charAt(i)*(10-i);
d1 = (d1 % 11);
if (d1<=1){
if (j<=2)
d1 = 1 - d1;
else
d1 = 0;}
else
d1 = 11 - d1;

if (rcpf2.charAt(0) != d1)
return aviso(rcpf1,“Título Eleitoral inválido.”);

d1 = 2;
for (i=9;i<11;i++)
d1 += rcpf1.value.charAt(i)
(13-i);
d1 = (d1 % 11);
if (d1<=1){
if (j<=2)
d1 = 1 - d1;
else
d1 = 0;}
else
d1 = 11 - d1;

if (rcpf2.charAt(1) != d1)
return aviso(rcpf1,“Título Eleitoral inválido.”);

return true;
}

function isInteger (s) {
var i;

if (isEmpty(s)) 
   if (isInteger.arguments.length == 1) return false;
 
for (i = 0; i < s.length; i++) {   
    var c = s.charAt(i);
    if (!isDigit(c)) return false;
}
return true;

}

function PoeZeros(valor,tam) {
//ntam = valor.value.length;
ntam = valor.length;
if (ntam != 0) {
zeros = ‘0000000000000’;
if (tam != ntam)
valor = zeros.substr(1,13-ntam)+valor;
return valor;
}
}

function aviso (campo, msg){
alert(msg);
campo.focus();
campo.select();
return false;
}
[/code]

Dê uma olhada, Lacerda. Numa dessas você decifre essa lógica.

Valeu.

VALEU UTILIZEI O VB

Desconhecimento meu… não sabia que tem como verificar o título eleitoral…
Ai vai o código em JavaScript…

function validaTitulo(titulo)
{
   var tit=titulo;
   var dig1=0;
   var dig2=0;

   //separa dados do titulo

    var tam = tit.length;
    var digitos= tit.substr(tam-2,2);
    var estado=  tit.substr(tam-4,2);
    var titulo=  tit.substr(0,tam-2);
    titulo='000000000000'+titulo;
    titulo=titulo.substr(titulo.length-11,titulo.length-1) ;
    var exce=(estado=='01')||(estado=='02');
    dig1= (titulo.charCodeAt(0)-48) *2 +  (titulo.charCodeAt(1)-48) *9 +  (titulo.charCodeAt(2)-48) *8 +            (titulo.charCodeAt(3)-48) *7 +            (titulo.charCodeAt(4)-48) *6 +            (titulo.charCodeAt(5)-48) *5 +            (titulo.charCodeAt(6)-48) *4 +            (titulo.charCodeAt(7)-48) *3 +            (titulo.charCodeAt(8)-48) *2;        var resto= (dig1  % 11);
    if (resto==0)
    {
     if (exce){
         dig1=1;
         }else{
             dig1=0;
         }
     }
     else
      {
      if (resto==1){
            dig1=0;}
               else {
                dig1=11-resto;
                    }
      }

     dig2= (titulo.charCodeAt(9)-48) *4 + (titulo.charCodeAt(10)-48) *3 + dig1*2;
     resto= (dig2  % 11);
     if (resto==0)
     {
      if (exce) {dig2=1;}
            else {dig2=0;}
     }
      else
     {
    if (resto==1)
     dig2=0;
    else dig2=11-resto;
  }

  if ( (digitos.charCodeAt(0)-48==dig1) && (digitos.charCodeAt(1)-48==dig2) )
  {
   document.form1.titulo.value=document.form1.titulo2.value;
   document.form1.submit();
  }
  else
  {
   alert("Título inválido");
  }
}

*Movi o tópico para off pq o assunto fugiu do tema :wink:

[]'s

r2_d2, por favor, nunca mais poste códigos em VB num forum de java :sad:

:lol: :lol: :lol: :lol:

Ô microfilo. Eu achei no google e coloquei pro cara pegar a lógica. Nada a ver.