# Como fazer a validação do CPF

**URL:** <https://community.glideapps.com/t/como-fazer-a-validacao-do-cpf/52841>\
**Category:** Ask for Help\
**Created:** [October 29, 2022, 12:38pm UTC](https://community.glideapps.com/t/como-fazer-a-validacao-do-cpf/52841 "2022-10-29T12:38:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![washington\_viana](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/washington_viana/32/19784_2.png) [@washington\_viana](https://community.glideapps.com/u/washington_viana)\
**Post date:** [October 29, 2022, 12:38pm UTC](https://community.glideapps.com/t/como-fazer-a-validacao-do-cpf/52841/1 "2022-10-29T12:38:36Z")

</div>

Preciso colocar dentro do aplicativo um validador de CPF

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [October 29, 2022, 2:52pm UTC](https://community.glideapps.com/t/como-fazer-a-validacao-do-cpf/52841/2 "2022-10-29T14:52:27Z")

</div>

I had to search to find out what a CPF is, but I think I figured it out and found some code.

Try placing this in a javascript column and set the p1 parameter to the column that contains your CPF.

```auto
if (p1!=null){
return validarCPF(p1);
} else {
return false;
}

function validarCPF(cpf) {	
	cpf = cpf.toString().replace(/[^\d]+/g,'');	
	if(cpf == '') return false;	
	// Elimina CPFs invalidos conhecidos	
	if (cpf.length != 11 || 
		cpf == "00000000000" || 
		cpf == "11111111111" || 
		cpf == "22222222222" || 
		cpf == "33333333333" || 
		cpf == "44444444444" || 
		cpf == "55555555555" || 
		cpf == "66666666666" || 
		cpf == "77777777777" || 
		cpf == "88888888888" || 
		cpf == "99999999999")
			return false;		
	// Valida 1o digito	
	add = 0;	
	for (i=0; i < 9; i ++)		
		add += parseInt(cpf.charAt(i)) * (10 - i);	
		rev = 11 - (add % 11);	
		if (rev == 10 || rev == 11)		
			rev = 0;	
		if (rev != parseInt(cpf.charAt(9)))		
			return false;		
	// Valida 2o digito	
	add = 0;	
	for (i = 0; i < 10; i ++)		
		add += parseInt(cpf.charAt(i)) * (11 - i);	
	rev = 11 - (add % 11);	
	if (rev == 10 || rev == 11)	
		rev = 0;	
	if (rev != parseInt(cpf.charAt(10)))
		return false;		
	return true;   
}

```

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/c/1c39cee4ac499a8ea3aaf9140a1d4636f5e80d0c.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/5/a5b60d39a1a9ea5eb7e369b0d1fc5b9e283de383.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/d/0d9ad112cfd4775e01f6cf00dc12f29864d388d4.png)

---

<div class="post-metadata">

**Author:** ![Manoel](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manoel/32/64525_2.png) [@Manoel](https://community.glideapps.com/u/Manoel)\
**Post date:** [September 27, 2023, 4:11pm UTC](https://community.glideapps.com/t/como-fazer-a-validacao-do-cpf/52841/3 "2023-09-27T16:11:14Z")

</div>

Flawless. Thanks!
