PC SOFT
ONLINE REPOSITORY
FOR WINDEVWEBDEV AND WINDEV MOBILE

Home |  | Sign in | English US
Valida CPF, CNPJ e Telefone com mascara e validação com Expressão Regular
Published by Boller
in the category Tools
New features



Description
Valida CPF, CNPJ e Telefone com mascara e validação com Expressão Regular
Illustrations, screen shots
none
none
User reviews
(To evaluate this resource, click 'Write a review')
Boller
ao entrar na janela

mascaras()
Boller
ao sair do campo

IF EDT_CPF <> "" THEN
IF Valida_CPF(EDT_CPF) = False THEN
EDT_CPF = ""
SetFocus(EDT_CPF)
ToastDisplay("CPF Inválido",toastLong,vaMiddle,haCenter,RGB(255,0,0))
END
END
Boller
// Summary: <specify the procedure action>
// Syntax:
//[ <Result> = ] Valida_Fone (<MyFone>)
//
// Parameters:
// MyFone:

// For instance:
PROCEDURE Valida_Fone(MyFone)

sCRegEx is string = "(([0-9]{2,3})|\([0-9]{2,3}\))[-. ]*(([0-9]{4,5})[-. ]*([0-9]{4}))$"

IF RegexMatch(MyFone,sCRegEx) = False THEN
RESULT False
ELSE
RESULT True
END
Boller
// Summary: <specify the procedure action>
// Syntax:
// Valida_CPF ()
//
// Parameters:
// None
// Return value:
// None
//
// For instance:
// Indicate an example.
//
PROCEDURE Valida_CPF(sGCpf is string)

Cpf is string = sGCpf
Cpf = Replace(Cpf,".","")
Cpf = Replace(Cpf,"-","")

IF Length(Cpf)<>11 THEN
MySelf = ""
RESULT(False)
END

// Caso coloque todos os numeros iguais
SWITCH Cpf
CASE "00000000000"
MySelf = ""
CASE "11111111111"
MySelf = ""
CASE "2222222222"
MySelf = ""
CASE "33333333333"
MySelf = ""
CASE "44444444444"
MySelf = ""
CASE "55555555555"
MySelf = ""
CASE "66666666666"
MySelf = ""
CASE "77777777777"
MySelf = ""
CASE "88888888888"
MySelf = ""
CASE "99999999999"
MySelf = ""
END

IF MySelf = "" OR Cpf = ""
RESULT(False)
ELSE

// calcula o primeiro digito
nSoma is int
nResto is int
nDigito_1, nDigito_2 is int

nSoma = (Val(Middle(Cpf,1,1)) * 10) + ...
(Val(Middle(Cpf,2,1)) * 09) + ...
(Val(Middle(Cpf,3,1)) * 08) + ...
(Val(Middle(Cpf,4,1)) * 07) + ...
(Val(Middle(Cpf,5,1)) * 06) + ...
(Val(Middle(Cpf,6,1)) * 05) + ...
(Val(Middle(Cpf,7,1)) * 04) + ...
(Val(Middle(Cpf,8,1)) * 03) + ...
(Val(Middle(Cpf,9,1)) * 02)

nResto = modulo(nSoma, 11)

IF nResto = 0 OR nResto = 1 THEN
nDigito_1 = 0
ELSE
nDigito_1 = 11 - nResto
END

// calculoa o segundo dígito
nSoma = (Val(Middle(Cpf,01,1)) * 11) + ...
(Val(Middle(Cpf,02,1)) * 10) + ...
(Val(Middle(Cpf,03,1)) * 09) + ...
(Val(Middle(Cpf,04,1)) * 08) + ...
(Val(Middle(Cpf,05,1)) * 07) + ...
(Val(Middle(Cpf,06,1)) * 06) + ...
(Val(Middle(Cpf,07,1)) * 05) + ...
(Val(Middle(Cpf,08,1)) * 04) + ...
(Val(Middle(Cpf,09,1)) * 03) + ...
(Val(Middle(Cpf,10,1)) * 02)

nResto = modulo(nSoma, 11)

IF nResto = 0 OR nResto = 1 THEN
nDigito_2 = 0
ELSE
nDigito_2 = 11 - nResto
END

sResultado is string

sResultado = NumToString(nDigito_1) + NumToString(nDigito_2)

//info(Val(Middle(cpf,10,2)) , Resultado)
//999.999.999-99

IF Val(Middle(Cpf,10,2)) = sResultado THEN
RESULT(True)
ELSE
MySelf = ""
ReturnToCapture(MySelf)
RESULT(False)
END

END
Boller
// Summary: <specify the procedure action>
// Syntax:
//[ <Result> = ] Valida_CNPJ (<scnpj> is string)
//
// Parameters:
// scnpj (ANSI string):

PROCEDURE Valida_CNPJ(scnpj is string)

//Limpa Campo
cnpj is string = scnpj
cnpj = Replace(cnpj ,".","")
cnpj = Replace(cnpj ,"-","")
cnpj = Replace(cnpj ,"/","")

IF Length(cnpj)<>14
RESULT(False)
END

// Caso coloque todos os numeros iguais
SWITCH cnpj
CASE"00000000000000"
MySelf=""
CASE"11111111111111"
MySelf=""
CASE"22222222222222"
MySelf=""
CASE"333333333333333"
MySelf=""
CASE"444444444444444"
MySelf=""
CASE"555555555555555"
MySelf=""
CASE"666666666666666"
MySelf=""
CASE"777777777777777"
MySelf=""
CASE"888888888888888"
MySelf=""
CASE"999999999999999"
MySelf=""
END

IF MySelf = ""
RESULT(False)
ELSE

// calcula o primeiro digito
LOC_num is int
LOC_num2 is int
LOC_num=(Val(Middle(cnpj,1,1)) *5) + ...
(Val(Middle(cnpj,2,1)) *4) + ...
(Val(Middle(cnpj,3,1)) *3) + ...
(Val(Middle(cnpj,4,1)) *2) + ...
(Val(Middle(cnpj,5,1)) *9) + ...
(Val(Middle(cnpj,6,1)) *8) + ...
(Val(Middle(cnpj,7,1)) *7) +...
(Val(Middle(cnpj,8,1)) *6) + ...
(Val(Middle(cnpj,9,1)) *5) + ...
(Val(Middle(cnpj,10,1)) *4) + ...
(Val(Middle(cnpj,11,1)) *3) + ...
(Val(Middle(cnpj,12,1)) *2)


LOC_num=modulo(LOC_num,11)
IF LOC_num<2 THEN
LOC_num=0
ELSE
LOC_num=11-LOC_num
END

// calculoa o segundo dígito
LOC_num2= (Val(Middle(cnpj,1,1)) *6) + ...
(Val(Middle(cnpj,2,1)) *5) + ...
(Val(Middle(cnpj,3,1)) *4) + ...
(Val(Middle(cnpj,4,1)) *3) + ...
(Val(Middle(cnpj,5,1)) *2) + ...
(Val(Middle(cnpj,6,1)) *9) + ...
(Val(Middle(cnpj,7,1)) *8) + ...
(Val(Middle(cnpj,8,1)) *7) + ...
(Val(Middle(cnpj,9,1)) *6) + ...
(Val(Middle(cnpj,10,1)) *5) + ...
(Val(Middle(cnpj,11,1)) *4) + ...
(Val(Middle(cnpj,12,1)) *3) + ...
(LOC_num) *2


LOC_num2=modulo(LOC_num2,11)
IF LOC_num2<2 THEN
LOC_num2=0
ELSE
LOC_num2=11-LOC_num2
END

Resultado is string

Resultado=NumToString(LOC_num) +NumToString(LOC_num2)

//99.999.999/0001-00 = 99999999000000
IF Val(Middle(cnpj,13,2)) =Resultado THEN
RESULT(True)
ELSE
MySelf = ""
RESULT(False)
END

END
Boller
// Summary: <specify the procedure action>
// Syntax:
// Mascaras ()
//
// Parameters:
// None
// Return value:
// None
//
// For instance:
// Indicate an example.
//
PROCEDURE Mascaras()

EDT_CPF.InputMask = "999.999.999-99"
EDT_CPF.Hint = "999.999.999-99"
EDT_CPF.ToolTip = "Digite o CPF"

EDT_CNPJ.InputMask = "99.999.999/9999-99"
EDT_CNPJ.Hint = "99.999.999/9999-99"
EDT_CNPJ.ToolTip = "Digite o CNPJ"

EDT_Fone.InputMask = "(99) 99999 9999"
EDT_Fone..Hint = "(99) 99999 9999"
EDT_Fone.ToolTip = "Digite o Telefone"
ABOUT
RATING:
51(1)
DOWNLOADS:
7
PUBLISHED:
July 12, 2021
VERSION:
26
CONCERNS:
WINDEV
Minimum version: 26
SIZE:
40.1 MB