Jump to content

CPF


Recommended Posts

a dias atrás tive necessidade de fazer a verificação de um CPF.

abaixo o código udsado:

Func checaCPF ($NCPF2)
    $soma = 0
    for $i=0 to 8
        $soma = $soma + (Int(StringMid($NCPF2,$i+1,1)) * (10 - $i))
     Next
    If $soma-(Int($soma/11)*11)<2 Then
       $1D=0
    Else
       $1D=11-($soma-(Int($soma/11)*11))
    EndIf
    If $1D<>StringLeft(StringRight($NCPF2,2),1) Then Return(0)
    $soma = 0;
    for $i=0 to 8
        $soma = $soma + (Int(StringMid($NCPF2,$i+1,1)) * (11 - $i))
     Next
    $soma=$soma+($1D*2)
    If $soma-(Int($soma/11)*11)<2 Then
       $2D=0
    Else
       $2D=11-($soma-(Int($soma/11)*11))
    EndIf
    If $2D<>StringRight($NCPF2,1) Then Return(0)
    Return(1)
 EndFunc

Pierre

Link to comment
Share on other sites

  • 2 years later...
  • 3 weeks later...

Boa tarde Pierre,

Vi o seu código de Validação de CPF, porém não consegui utilizá-lo. Tem como você me passar maiores detalhes?

Obrigado!

Angelo

Chame a função informando o cpf, se for válido retorna 1 e se não for retorna 0.

Exemplo:

$CPF=InputBox("","CPF")

If checacpf($CPF)=1 Then

MsgBox(0,"","CPF OK")

Else

MsgBox(0,"","CPF inválido")

EndIf

Exit

Link to comment
Share on other sites

yes!

Here's my try (hope you don't mind):

Func _checaCPF($NCPF2)
    
    If StringLen($NCPF2) - 11 Then
        Return False
    EndIf
    
    Local $v1
    For $i = 0 To 8
        $v1 += Number(StringMid($NCPF2, $i + 1, 1)) * (10 - $i)
    Next
    $v1 = 11 - Mod($v1, 11)
    $v1 *= $v1 < 10
    
    If Not $v1 = Number(StringMid($NCPF2, 10, 1)) Then
        Return False
    EndIf
    
    Local $v2
    For $i = 0 To 8
        $v2 += Number(StringMid($NCPF2, $i + 1, 1)) * (11 - $i)
    Next
    $v2 = 11 - Mod($v2 + 2 * $v1, 11)
    $v2 *= $v2 < 10
    
    Return $v2 = Number(StringRight($NCPF2, 1))
    
EndFunc

língua portuguesa - one of my favorites

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...