> For the complete documentation index, see [llms.txt](https://help.cosmobots.io/help/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.cosmobots.io/help/outros/dicas/validar-cpf.md).

# Validar CPF

1- Para isso, crie uma mensagem que pergunte o CPF do usuário e salve a resposta como usuário CPF:

![](/files/-MickNlR99UEe29UUAym)

{% hint style="info" %}
Caso não tenha esse campo em sua lista de opções crie um novo campo.
{% endhint %}

3- Crie uma etapa JavaScript e insira o seguinte código:

```
var strCPF = user.cpf;

function testaCPF(strCPF) {
	var soma;
	var resto;
	soma = 0;
	if (strCPF == "00000000000") return false;

	for (var i = 1; i <= 9; i++) soma = soma + parseInt(strCPF && strCPF.substring(i - 1, i)) * (11 - i);
	resto = (soma * 10) % 11;

	if ((resto == 10) || (resto == 11)) resto = 0;
	if (resto != parseInt(strCPF && strCPF.substring(9, 10))) return false;

	soma = 0;
	for (i = 1; i <= 10; i++) soma = soma + parseInt(strCPF && strCPF.substring(i - 1, i)) * (12 - i);
	resto = (soma * 10) % 11;

	if ((resto == 10) || (resto == 11)) resto = 0;
	if (resto != parseInt(strCPF.substring(10, 11))) return false;
	return true;
}


if (testaCPF(strCPF) === true) {
	context.resposta = "ok"
} else {
	context.resposta = "nok"

}

console.log(testaCPF && strCPF);
console.log(context.resposta);
```

4- Crie um Filtro, e no filtro coloque a seguinte condição e salve:

![](/files/-MickpMn54vAEAVy7BOB)

5- Do lado não do filtro, insira a mensagem que deve ser enviada ao usuário caso ele informe o CPF incorreto:

![](/files/-MicksF605LWVrYPzmrL)

6- Depois crie uma etapa existente e direcione novamente a etapa que pergunta o CPF.

![](/files/-MickvFSY3YcePCTxNrR)

7- Prontinho, se o CPF do usuário estiver incorreto ele vai receber a mensagem informando.

![](/files/-MiclNDHZqITQ6pqQ4qd)
