Validar CPF

Cableguy

Expert
Licensed User
Longtime User
Procura Bem no forum, utiliza "show numeric keyboard", e deves encontrar o que precisas
 

Felippy Rocha

New Member
Licensed User
Longtime User
Public Sub DVCPF(cpf As String) As Boolean
Dim cpf1, cpf2, controle As String
Dim contini, contfim, soma, dígito As Int
Dim i, ii As Int

Try

cpf1 = cpf
cpf2 = sf.Right(cpf, 2)

controle = ""
contini = 2
contfim = 10

For ii = 1 To 2

soma = 0

For i = contini To contfim
soma = soma + (sf.Mid(cpf1, i - ii, 1) * (contfim + 1 + ii - i))
Next

If ii = 2 Then soma = soma + (2 * dígito)
dígito = (soma * 10) Mod 11
If dígito = 10 Then dígito = 0
controle = controle & sf.Trim(dígito)
contini = 3
contfim = 11

Next

If controle <> cpf2 Then
Return False
Else
If sf.Len(cpf) <> 11 Then
Return False
Else
Return True
End If
End If

Catch

Msgbox ("Ocorreu um erro ao validar CPF." & CRLF & "Erro:" & LastException.Message ,"RF-Mobile")

Return False

End Try

End Sub
 
Top