Categorias

Validar número do PIS/PASEP

Com essa função é possível fazer a validação do número do PIS/PASEP passado por parametro.
A função retorna True para quando o número é verdadeiro e False para um número inválido.

<%
'-----------------------------------------------------
'Funcao: IsPISPASEP(BYVal strPISPASEP)
'Sinopse: Verifica se o valor passado é um PISPASEP 
'         válido
'Parametro: strPISPASEP
'Retorno: Booleano
'Autor: Gabriel Fróes - www.codigofonte.com.br
'-----------------------------------------------------
Function IsPISPASEP(BYVal strPISPASEP)
    Dim strPeso
    Dim intTotal
    Dim intCont
    Dim intResultado

    intTotal = 0
    strPeso = "3298765432"
    
    'Validando a entrada dos dados
    If strPISPASEP = "" Or  Len(strPISPASEP) <> 11 Then
        IsPISPASEP = False
        Exit Function
    End If
    
    For intCont = 1 To 10
        intResultado = Mid(strPISPASEP, intCont, 1) * Mid(strPeso,intCont, 1)
        intTotal = intTotal + intResultado
    Next
    
    'Resto da Divisao
    intResto = intTotal Mod 11
    
    If intResto <> 0 Then 
        intResto = 11 - intResto
    End If
    
    If intResto = 10 Or intResto = 11 Then
        intResto = Mid(intResto, 2, 1)
    End If

    If Cint(intResto) <> Cint(Mid(strPISPASEP, 11, 1)) Then
        IsPISPASEP = False
        Exit Function
    End If    
    
    IsPISPASEP = True
    
End Function 
%>

Testando o código:
<% If IsPISPASEP("12660277515") Then %> O PISPASEP está Correto! <% Else %> O PISPASEP está Incorreto! <% End If %>